What's going to replace std.stream?

Jakob Ovrum via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 6 00:24:59 PST 2016


On Saturday, 6 February 2016 at 06:29:56 UTC, cy wrote:
> Let's say I have a socket, and a file, and I want to send the 
> contents of that file to the socket. What's the best way to do 
> that? Yes I'm aware that in Linux, you can use a combination of 
> a pipe and splice(2) to keep all buffers kernel side for that, 
> but I was thinking more generally. The traditional C way is to 
> read() into a buffer, then write() it out, until the input is 
> exhausted. But apparantly in D we're not supposed to do that?
>
> It's just that I tried to use std.stream, and found that the 
> whole module had been marked as deprecated some time last year. 
> What exactly is going to replace it? Some sort of lazy file 
> contents accessor, that can take advantage of zero copy things 
> like splice() when hooked together? A source/sink paradigm 
> maybe?
>
> I don't see anything analagous to what std.stream does in 
> phobos... has it just not been made public yet?

There are some third party libraries that implement streams [1], 
but your example can be done like:

foreach(chunk; File("path/to/file").byChunk(16 * 1024))
     socket.write(chunk);

[1] e.g. http://code.dlang.org/packages/io


More information about the Digitalmars-d-learn mailing list