I've a video file about 2GB in size. This header of video file is encrypted (approximately 528 bytes encrypted). In order to Decrypt this video file i'm reading all bytes from the file into an NSData object. As soon as i write this file into NSData object my Application crashes(possibly b'coz max-256MB RAM for iPad).
So how do i go about storing this NSData object into Virtual memory of an iPad/ iPhone temporarily?
Any other approach by means of which i can achieve the same?
Use an NSInputStream
to read in the file piece by piece so you aren't loading it all into memory all at once. Specifically you'll want to make use of hasBytesAvailable
and read:maxLength:
.
Something like:
NSInputStream *myStream = [NSInputStream inputStreamWithFilAtPath:pathToAbsurdlyLargeFile];
[myStream open];
Byte buffer[BUFFER_SIZE];
while ([myStream hasBytesAvailable])
{
int bytesRead = [myStream read:buffer maxLength:BUFFER_SIZE];
NSData *myData = [NSData dataWithBytes:buffer length:bytesRead];
// do other stuff...
}
[myStream close];
Note that you may not need to create an NSData object. You just mentioned you were using it, so I threw it in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With