Read only “N” bytes from a file in Cocoa
How to read only "N" bytes from a specified file? If you want random access to the contents of the file in a manner similar to having loaded it via NSData but without actually reading everything into memory, you can use memory mapping. Doing so means that the file on disk becomes treated as a section of virtual memory, and will be paged in and out just like regular virtual memory. NSError * error = nil; NSData * theData = [NSData dataWithContentsOfFile: thePath options: NSMappedRead error: &error]; If you don't care about getting filesystem error details, you can just use: NSData * theData =