Sometimes, we want to convert a Buffer into a ReadableStream in Node.js.
In this article, we’ll look at how to convert a Buffer into a ReadableStream in Node.js.
How to convert a Buffer into a ReadableStream in Node.js?
To convert a Buffer into a ReadableStream in Node.js, we call the Readable.from
method.
For instance, we write
const { Readable } = require("stream");
const stream = Readable.from(myBuffer.toString());
to call Readable.from
with the myBuffer
buffer converted to a string to convert myBuffer
to a readable stream.
Conclusion
To convert a Buffer into a ReadableStream in Node.js, we call the Readable.from
method.