Idiomatic representation of { buffer, bytesRead }

Kevin Smith zenparsing at
Thu Mar 5 16:42:39 UTC 2015

> > But you can support both, like this:
> >
> >     pull(DataView) -> Promise<DataView>
> >     pull(TypedArrayView) -> Promise<TypedArrayView of the same type>
> >
> > A view argument conveniently provides just the three pieces of
> information
> > you need, plus a type.
> I thought of that. However, I found it a bit strange that passing this
> function a view onto bytes [256, 512] of a 1024-byte buffer would detach
> the entire 1024-byte buffer. What do you think?

Not sure if it makes any difference or not, but it's interesting to me that
a signature like the above maps very well to async iterators: -> Promise<DataView>

I implemented a zip/tar utility when validating the async iterator design
and basically used that signature (except with Node Buffers instead of
DataViews).  The basic strategy I used was to construct a pipeline with
async iterators:

    source -> data pump -> transform -> data pump -> consumer

where each "data pump" would have a pool of buffers, and would pull from
the upstream iterator, providing the next unused buffer in its pool as
argument to "next".  The downstream transform or consumer would then just
pull the next filled buffer (view) from the upstream pool.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list