What are my options to pipe stream to a variable? Based on this documentation the examples of writable stream include:
So does it mean I cannot pipe stream to a variable to process it? In fact I dont want to save the stream on my disk, so what is the best way to pipe all of the streams and use that data?
Thanks please let me know if you need more clarification!
You probably can pipe a stream to a variable, but pipe is generally used to pipe the stream to some other method that can utilize the stream, as pipe pulls all the data out of a readable stream, and writes it to the supplied destination, automatically managing the flow so that the destination is not overwhelmed by a fast readable stream.
For instance, piping a stream to a file
someReadableStream.pipe(fs.createWriteStream("result.json"));
If you just want the data in a variable, there are events for that, that are probably easier to use, like on('data')
var readable = getReadableStreamSomehow(),
result = '';
readable.on('data', function(chunk) {
result += chunk;
});
readable.on('end', function () {
// do something with "result"
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With