On 9/26/10 23:34 PDT, Shin Fujishiro wrote:
Thus I think we need a buffering layer that exposes a randomly
accessible array to upper layers.  ByLine() can be easily and
efficiently implemented with the following primitives defined:

Buffer
{
     // The entire buffer.
     ubyte[] buffer();

     // Slice of buffer() where data is available.
     ubyte[] available();

     // Moves the beginning of available() by n in buffer().
     void bump(sizediff_t n);

     // Reads next blob from a source.
     bool fetch();
}

Yes, cstdio-esque rawRead() is no good for high-level ByLine.  What
high-level I/O entities want is:  A randomly accessible buffer. Device
handles may expose block-oriented streaming primitives, but they
must be made "partially random accessible" by the buffering layer.

But that's too big an interface. When would one ever need buffer[], when the beginning and the end of the buffer may be used for different portions of the input?

A better stream interface, which actually extends the standard input range interface:

struct Stream(T)
{
    @property T[] front();
    void munchFront(size_t bytes) in { assert(bytes <= front.length; }
    bool empty();
    void popFront();
}

This still doesn't allow filling the buffer with a new line, but it does offer the ability to a client to copy lines into its own buffer.

Andrei
_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to