Source

MYUtilities / MYChecksum.m

Full commit
//
//  MYChecksum.m
//  MYUtilities
//
//  Created by Jens Alfke on 7/3/10.
//  Copyright 2010 Jens Alfke. All rights reserved.
//

#import "MYChecksum.h"
#include <zlib.h>

@implementation NSData (MYChecksum)


/** Computes the Adler32 checksum/digest/hash of the data. */
- (UInt32) my_adler32 {
    UInt32 initialAdler = (UInt32) adler32(0L, Z_NULL, 0);
    return (UInt32) [self my_adler32: initialAdler];
}

/** Updates a running Adler32 checksum/digest/hash with this data. */
- (UInt32) my_adler32: (UInt32)prevAdler32 {
    return (UInt32) adler32(prevAdler32, self.bytes, (uInt)self.length);
}


@end