[phobos] Improvement of stream
Andrei Alexandrescu
andrei at erdani.com
Sun Jul 4 22:37:08 PDT 2010
Hello,
I've been looking over the streaming proposal. Allow me to make a few
comments:
- The input ranges _are_ intended to be input streams, and the output
ranges _are_ intended to be output streams. If they don't fulfill that
purpose, they should be changed (instead of adding new categories).
- Input streams have the read primitive. What is wrong with an input
range of ubyte[]? Then accessing front() gives you a buffer and popFront
reads in a new buffer.
- What does flush() do for input streams?
- I don't think close() is a good primitive for an input stream. An
input stream should originate in a connection handle, and it's the
handle, not the stream, that should control the connection. For example:
auto s = Socket("123.456.455.1");
auto stream = s.byChunk(1024 * 16);
... stream is an input range of ubyte[] ...
s.close();
If the range defines a close() operation, then we need to start talking
about it defining an open() operation, which complicates matters. Why
not leave ranges for traversal and handles for connections?
- On to output streams. What's wrong with having an output range of
ubyte[]? Its put() primitive would be the same as the proposed write()
routine.
- flush() would be a good optional addition to an output stream.
- I have the same feeling about close() for output streams.
- The Seekable idea is good, I was thinking of it for a while. It
expresses a range that is not as cheap for random access as a
random-access range, but also that makes random seeking possible. What
kind of algorithms could use Seekable?
- What's the purpose of StreamWrapper? And why is it reading in the
write() primitive?
- ByLine is a bit awkward because it needs to read buffers of size 1.
Clearly there is some problem there. The right way is to build
ByLine!Char on top of a stream of Char, not a stream of Char[].
(Speaking of which, I just checked in BlockingInputReader. It does read
one character at a time but it has an inefficiency caused by the FILE*
interface.)
- What does FileStream do that File doesn't or can't do?
Let me know of what you think.
Andrei
On 06/30/2010 11:48 AM, SHOO wrote:
> In Japanese community, improvement of stream is discussed.
>
> New stream has following characteristics.
>
> - Supporting Range
> - Duck typing
> - Accepting interface optionally (main is struct)
>
> Very simple draft is here:
> http://ideone.com/BU3ev
>
> Now, satoru_h ( http://twitter.com/satoru_h ) works for more.
>
> What do you think?
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
More information about the phobos
mailing list