Streaming library

Denis Koroskin 2korden at gmail.com
Fri Oct 15 14:12:33 PDT 2010


On Sat, 16 Oct 2010 01:01:33 +0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 10/15/10 15:54 CDT, Kagamin wrote:
>> Andrei Alexandrescu Wrote:
>>
>>> Whatever interface(s) we find work best for various kinds of streams,  
>>> we
>>> should make them play nice with ranges. Burst streams (the kind that
>>> offer data in variable-size chunks) work great with a range interface.
>>
>> I was thinking about chunk size to be supplied by user like this
>>
>> int readInt()
>> {
>>    ubyte[] buffer=read(4);
>>    assert(buffer.length==4); // can this trigger?
>>    return *cast(int*)buffer.ptr;
>> }
>

ubyte[] read() and ubyte[] read(size_t size) both require buffering (e.g.  
BufferedStream adapter). As such, it can provide stronger guaranties over  
raw streams.

> That's a fair point. I don't think you can assert, there could always be  
> the situation that there was not enough data. Anyhow, wrt byChunk I was  
> thinking of adding a property for changing the chunk size prior to  
> popFront():
>
> auto chunks = File("file.bin").byChunk(8);
> // now chunks.front() is a ubyte[] containing 8 bytes
> chunks.chunkSize = 4;
> chunks.popFront();
> // now chunks.front() is a ubyte[] containing 4 bytes
> chunks.chunkSize = 4096;
> for (; !chunks.empty; chunks.popFront()) {
>      // handle 4KB at a time
> }
>
>
> Andrei


More information about the Digitalmars-d mailing list