Streaming library
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Oct 15 14:01:33 PDT 2010
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;
> }
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