I’m trying to modify tiny chunks (32 bytes) of large (hundreds of MB) .wav audio files.
Currently I load the files using
[NSData dataWithContentsOfURL:]
modify the bytes, and save the file using
[data writeToURL:].
Is there a convenient way to modify a binary file without loading it into RAM?
edit:
The following stdio functions work for me:
NSUInteger myOffset = 8;
const char *myBytes = myData.bytes;
NSUInteger myLength = myData.length;
FILE *file = fopen([[url path] cStringUsingEncoding:NSASCIIStringEncoding], "rb+");
assert(file);
fseek(file, myOffset, SEEK_CUR);
fwrite(myBytes, 1, myLength, file);
fclose(file);
yes, you would use a lower level approach such as
fopento avoid repeatedly loading/reloading the file viaNSData(as you have found and mentioned in your update). this is the level i work at for audio file I/O.if you want a Foundation type, you may want to try
NSFileHandle.