Categories
JavaScript Answers

How to convert a Buffer into a ReadableStream in Node.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *