Re: reading in text files
Re: reading in text files
- Subject: Re: reading in text files
- From: Malte Tancred <email@hidden>
- Date: Mon, 4 Feb 2002 17:17:36 +0100
On monday, february 4, 2002, at 06:11 , Bob Savage wrote:
...
But if we are managing an additional buffer we can't be providing this
method as a category on NSFileHandle. Again, if this were to be
desired, it
should be implemented properly by the folks at Apple.
...
In case anyone is interested, the `final` form of
NSFileHandle(delimiting)
can be found here:
<http://homepage.mac.com/bobsavage/Programming/delimiting/index.html>
I don't really think that the suggested search functionality belongs in
NSFileHandle. The responsibility of NSFileHandle is to...uh... represent
a file handle. Ie, basic I/O operations like read and write (and perhaps
even those belong in classes of their own).
Buffering and scanning should be handled on a level above the basic I/O
routines.
With a well designed I/O API including eg NSReader, NSBufferedReader
etc, a lot of tasks related to reading and scanning sequences of bytes
would become quite simple.
And unified:
Need to find all lines in a HUGE 2GB file?
Create a reader with an NSData (memory mapping the file) as it's
``source''.
Need to find all lines read from a socket?
Create a reader with an NSFileHandle as it's ``source''.
Need process all lines, one by one, from a file without reading it
all into memory nor memory mapping it?
Create a reader with an NSFileHandle as it's ``source''.
Then the ``byte scanner'' that operates on a ``reader'' can be used to
find the lines. That's _the same_ scanner class for each case.
Nice eh?! :-)
Again, as I wrote some days ago, it would be nice if Foundation was
extended with something similar to the java.io and java.net classes.
And please note that I don't request the existing classes be removed.
They are indeed both powerful and easy to work with as they are. I
simply argue that a few additional classes would make life a lot easier,
responsibilities clearer and method implementations shorter.
Cheerio,
Malte
--
Malte Tancred
Computer programmer, Oops AB, Sweden
mailto:email@hidden
http://www.oops.se/