Stream Proposal
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Mar 11 18:36:15 PST 2011
On 3/11/11 6:29 PM, dsimcha wrote:
> The discussion we've had here lately about reading gzipped files has proved
> rather enlightening. I therefore propose the following high-level design for
> streams, with the details to be filled in later:
>
> 1. Streams should be built on top of input and output ranges. A stream is
> just an input or output range that's geared towards performing I/O rather than
> computation. The border between what belongs in std.algorithm vs. std.stream
> may be a bit hazy.
1a. Formatting should be separated from transport (probably this is the
main issue with std.stream).
A simple input buffered stream of T would be a range of T[] that has two
extra primitives:
T[] lookAhead(size_t n);
void leaveBehind(size_t n);
as discussed earlier in a related thread. lookAhead makes sure the
stream has n Ts in the buffer (or less at end of stream), and
leaveBehind "forgets" n Ts at the beginning of the buffer.
I'm not sure there's a need for formalizing a buffered output interface
(we could simply make buffering transparent, in which case there's only
need for primitives that get and set the size of the buffer).
In case we do want to formalize an output buffer, it would need
primitives such as:
T[] getBuffer(size_t n);
void commitBuffer(size_t n);
Andrei
More information about the Digitalmars-d
mailing list