Skip to content

Instantly share code, notes, and snippets.

@nelsonfncosta
Created April 22, 2021 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsonfncosta/896323112f381fefad4b01412c047e7e to your computer and use it in GitHub Desktop.
Save nelsonfncosta/896323112f381fefad4b01412c047e7e to your computer and use it in GitHub Desktop.
Example of converting a stream to a string
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