Created
October 10, 2019 20:27
-
-
Save wpscholar/270005d42b860b1c33cf5ab25b37928a to your computer and use it in GitHub Desktop.
Convert a buffer to a stream in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert a buffer to a stream | |
* | |
* @param binary Buffer | |
* @returns Readable | |
*/ | |
function bufferToStream(binary) { | |
return new Readable({ | |
read() { | |
this.push(binary); | |
this.push(null); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use https://github.com/stream-utils/stream-to-array combined with
Buffer.concat(array)
to turn a stream into a buffer.