ZDCFileChecksum

@interface ZDCFileChecksum : NSObject

ZDCFileChecksum can generate 1 or more checksums of a file in a single pass. It supports all the algorithms in the S4Crypto library.

  • Convenience method for checksuming an entire file with the given algorithm.

    Declaration

    Objective-C

    + (nullable NSProgress *)
        checksumFileURL:(nonnull NSURL *)fileURL
          withAlgorithm:(id)algorithm
        completionQueue:(nullable dispatch_queue_t)completionQueue
        completionBlock:(nonnull void (^)(NSData *_Nullable,
                                          NSError *_Nullable))completionBlock;

    Swift

    class func checksumFileURL(_ fileURL: URL, withAlgorithm algorithm: Any!, completionQueue: DispatchQueue?, completionBlock: @escaping (Data?, Error?) -> Void) -> Progress?

    Parameters

    fileURL

    A valid file URL.

    algorithm

    The hash algorithm to use. E.g.: kHASH_Algorithm_SHA1

    completionQueue

    The dispatch_queue to invoke the completionBlock on. If NULL, the main queue will be used.

    completionBlock

    This block will be called once the checksum process has completed. If an error occurred, the error value will be set, and the checksum value should be ignored.

    Return Value

    progress The progress can be used to monitor the process, or to cancel it (via [progress cancel]).

  • Convenience method for checksuming an entire stream with the given algorithm.

    @params streamSize The NSInputStream class has no way of getting the total length. So if you want the progress to be determinate, you’ll need to pass the length explicitly.

    Declaration

    Objective-C

    + (nullable NSProgress *)
        checksumFileStream:(nonnull NSInputStream *)fileStream
            withStreamSize:(uint64_t)streamSize
                 algorithm:(id)algorithm
           completionQueue:(nullable dispatch_queue_t)completionQueue
           completionBlock:(nonnull void (^)(NSData *_Nullable,
                                             NSError *_Nullable))completionBlock;

    Swift

    class func checksumFileStream(_ fileStream: InputStream, withStreamSize streamSize: UInt64, algorithm: Any!, completionQueue: DispatchQueue?, completionBlock: @escaping (Data?, Error?) -> Void) -> Progress?

    Parameters

    fileStream

    The input stream to read from.

    algorithm

    The hash algorithm to use. E.g.: kHASH_Algorithm_SHA1

    completionQueue

    The dispatch_queue to invoke the completionBlock on. If NULL, the main queue will be used.

    completionBlock

    This block will be called once the checksum process has completed. If an error occurred, the error value will be set, and the checksum value should be ignored.

    Return Value

    progress The progress can be used to monitor the process, or to cancel it (via [progress cancel]).

  • Starts a checksum process to read given file, and calculate the checksum(s).

    Declaration

    Objective-C

    + (nullable NSProgress *)
         checksumFileURL:(nonnull NSURL *)fileURL
        withInstructions:
            (nonnull NSArray<ZDCFileChecksumInstruction *> *)instructions
                   error:(NSError *_Nullable *_Nullable)errorPtr;

    Swift

    class func checksumFileURL(_ fileURL: URL, with instructions: [ZDCFileChecksumInstruction]) throws -> Progress

    Parameters

    fileURL

    A valid file URL.

    instructions

    A list of checksum operations to perform. The method will process the instructions, and automatically determine how to peform the optimum IO.

    errorPtr

    If an error occurs while validating the parameters, or trying to setup the IO, then nil will be returned, and this param (if non-nil) will be set with an error explaining the problem.

    Return Value

    progress The progress can be used to monitor the process, or to cancel it (via [progress cancel]).

  • Starts a checksum process to read given file, and calculate the checksum(s).

    @params streamSize The NSInputStream class has no way of getting the total length. So if you want the progress to be determinate, you’ll need to pass the length explicitly.

    Declaration

    Objective-C

    + (nullable NSProgress *)
        checksumFileStream:(nonnull NSInputStream *)fileStream
            withStreamSize:(uint64_t)streamSize
              instructions:
                  (nonnull NSArray<ZDCFileChecksumInstruction *> *)instructions
                     error:(NSError *_Nullable *_Nullable)errorPtr;

    Swift

    class func checksumFileStream(_ fileStream: InputStream, withStreamSize streamSize: UInt64, instructions: [ZDCFileChecksumInstruction]) throws -> Progress

    Parameters

    fileStream

    A valid file input stream.

    instructions

    A list of checksum operations to perform. The method will process the instructions, and automatically determine how to peform the optimum IO.

    errorPtr

    If an error occurs while validating the parameters, or trying to setup the IO, then nil will be returned, and this param (if non-nil) will be set with an error explaining the problem.

    Return Value

    progress The progress can be used to monitor the process, or to cancel it (via [progress cancel]).