Skip to content

Instantly share code, notes, and snippets.

View Vyazovoy's full-sized avatar

Andrey Vyazovoy Vyazovoy

  • Squarespace, Inc.
  • New York, US
View GitHub Profile
@Vyazovoy
Vyazovoy / NSData+PSPDFFoundation.m
Created November 14, 2015 18:19 — forked from steipete/NSData+PSPDFFoundation.m
Haven't done much with dispatch_io yet so I'd appreciate a few more eyeballs on this. Am I closing things correctly in all error conditions? Are there other knobs I could change to make things even faster? (I know I've been lazy on the NSError's)
static NSData *PSPDFCalculateSHA256FromFileURL(NSURL *fileURL, CC_LONG dataLength, NSError **error) {
NSCParameterAssert(fileURL);
dispatch_queue_t shaQueue = dispatch_queue_create("com.pspdfkit.sha256-queue", DISPATCH_QUEUE_SERIAL);
__block dispatch_io_t readChannel;
void (^processIntError)(int intError) = ^(int intError) {
if (intError != 0) {
PSPDFLogWarning(@"Stream error: %d", intError);
if (error) *error = [NSError errorWithDomain:@"SHA256Error" code:100 userInfo:@{NSLocalizedDescriptionKey: @"failed to open file for calculating SHA256."}];