kawanet / msgpack-lite

Fast Pure JavaScript MessagePack Encoder and Decoder / msgpack.org[JavaScript]
https://www.npmjs.com/package/msgpack-lite
MIT License
991 stars 128 forks source link

Is it possible to read only one msgpack (ie. a header) from a stream, then leave the rest intact? #72

Open stuartpb opened 7 years ago

stuartpb commented 7 years ago

I'm looking at the streaming interface, but one thing isn't clear to me: is it possible to pipe a file stream to a decoder stream to read a msgpack value in the file, then unpipe it and begin reading the rest of the file immediately from the octet following the msgpack value, outside the context of a msgpack stream?

stuartpb commented 7 years ago

The simplest way I can think to do this is to add a bottleneck on the stream going into the DecodeStream that breaks each chunk into a series of chunks byte-by-byte, then unpipes after the finishing byte that causes an object to be emitted.

However, I'm wondering if there's another way, such as a modification to the flush method (and/or the fetch method) that would allow for another method that could be called to get any buffered data that ha yet to be flushed, in the middle of the first call of the DecodeStream's data callback.

stuartpb commented 7 years ago

The dryrun measuring feature described in #40 could also be useful here.