Created
May 29, 2014 08:45
-
-
Save interchen/6bc60e78fc599baa99f3 to your computer and use it in GitHub Desktop.
block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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