Skip to content

Instantly share code, notes, and snippets.

@interchen
Created May 29, 2014 08:45
Show Gist options
  • Select an option

  • Save interchen/6bc60e78fc599baa99f3 to your computer and use it in GitHub Desktop.

Select an option

Save interchen/6bc60e78fc599baa99f3 to your computer and use it in GitHub Desktop.
block
// We don't need to keep making new NSData objects. We can just use one repeatedly.
__block NSMutableData *data = [NSMutableData dataWithLength:blockSize];
__block RNEncryptor *decryptor = nil;
dispatch_block_t readStreamBlock = ^{
[data setLength:blockSize];
NSInteger bytesRead = [cryptedStream read:[data mutableBytes] maxLength:blockSize];
if (bytesRead < 0) {
// Throw an error
}
else if (bytesRead == 0) {
[decryptor finish];
}
else {
[data setLength:bytesRead];
[decryptor addData:data];
NSLog(@"Sent %ld bytes to decryptor", (unsigned long)bytesRead);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment