Feedback on Streams concept, similar to Ranges

Jacob Shtokolov jacob.100205 at gmail.com
Thu May 18 01:31:21 UTC 2023


On Monday, 15 May 2023 at 09:53:22 UTC, Andrew wrote:
> So, I'd appreciate if anyone could take a look at my project, 
> tell me if you think this is a good idea or not, if I should 
> introduce a DIP for this change if added to Phobos (I know the 
> DIP process is closed at the moment), or if you have any other 
> feedback for this.

First of all, thanks for investing your time into this!

Have got some questions:

1. Have you looked at the 
[IOPipe](https://github.com/schveiguy/iopipe) library?
2. What are the main benefits over the existing Ranges concept? 
Say, given your example:

```d
import streams;

void readFileTo(S)(string filename, S stream) if 
(isOutputStream!(S, ubyte)) {
     import std.stdio;
     auto fIn = FileInputStream(filename);
     transferTo(fIn, stream);
}
```

With ranges, this would look something like:

```d
import std;

void readFileTo(S)(string filename, ref S stream) if 
(isOutputRange!(S, ubyte[])) {
     File(filename).byChunk().copy(stream);
}
```

Which is more or less the same.

3. In the README you write:

```
Phobos' concept of an Input Range relies on implicit buffering of 
results... This doesn't map as easily to many low-level resources
```

AFAIK, the read/write buffers are anywhere, except, probably, 
`sendfile()` and some combination of `mmap` and `write`. But I'm 
struggling to get how this streams concept maps onto `sendfile` 
as well.


More information about the Digitalmars-d mailing list