Created
April 22, 2021 22:11
-
-
Save nelsonfncosta/896323112f381fefad4b01412c047e7e to your computer and use it in GitHub Desktop.
Example of converting a stream to a string
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
function streamToString (stream) { | |
const chunks = [] | |
return new Promise((resolve, reject) => { | |
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk))) | |
stream.on('error', (err) => reject(err)) | |
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment