Why you should use -availableData rather than -readDataToEndOfFile
(All of this only applies to regular files, not to “communications channels”, which I interpret to mean sockets and pipes. Also, this only matters on a 64-bit Mac; on a 32-bit system, you will run out of memory long before seeing any difference between these two methods.)
- -[NSFileHandle availableData]:
- “If the receiver is a file, returns the data obtained by reading the file from the file pointer to the end of the file.”
- -[NSFileHandle readDataToEndOfFile]:
- “The data available through the receiver up to UINT_MAX bytes (the maximum value for unsigned integers) …”
In other words, if there are more than UINT_MAX bytes in the file, -availableData will return all of them, whereas -readDataToEndOfFile will only return the first UINT_MAX of them.
October 26th, 2006 at 05:44:30
Note that this assumes the documentation to tell the truth, the whole truth, and nothing but the truth. ;)