On 17 May 2014, at 9:46 am, William Squires <wsqui...@satx.rr.com> wrote:
> Also, how come NSFileHandle doesn't have a -[NSFileHandle > readFileWithSeparator:(NSString *)] method so one can read in only chunks of > a file (of varying size, such as CSV records, or lines in a text file, > separated by \n, as opposed to a fixed size, which could be accomplished with > -[NSFileHandle readDataOfLength:(NSUInteger)] instead), instead of having to > read in the whole thing? Because that breaks an important abstraction of NSFileHandle, which is that it is not concerned with any aspect of what the data represents. That's a higher-level concept. To seek as far as a specific character or byte sequence requires that it actually examines the bytes one at a time, whereas the current API just reads fixe-sized chunks very efficiently. You could certainly subclass NSFileHandle and create your own NSTextFileHandle and that could seek until a particular byte sequence, but the price you'll pay for that convenience is much poorer performance. It might be OK for your needs however. Essentially, Apple provide a lowest-common denominator class here that can be used in many different cases unchanged, and without having to understand anything about the data stream. Above that, it's up to you. I agree that reading a file broken into lines is a common need, but it raises questions, like what text encoding is the file in? Typically, you'll have to read data in chunks, convert to a string, and maybe use NSScanner to locate a byte sequence. --Graham _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com