How to wrap a buffer as a stream2 Readable stream?

后端 未结 3 1328
日久生厌
日久生厌 2020-11-29 02:02

How can I transform a node.js buffer into a Readable stream following using the stream2 interface ?

I already found this answer and the stream-buffers module but thi

3条回答
  •  眼角桃花
    2020-11-29 02:24

    As natevw suggested, it's even more idiomatic to use a stream.PassThrough, and end it with the buffer:

    var buffer = new Buffer( 'foo' );
    var bufferStream = new stream.PassThrough();
    bufferStream.end( buffer );
    bufferStream.pipe( process.stdout );
    

    This is also how buffers are converted/piped in vinyl-fs.

提交回复
热议问题