Created
March 15, 2023 21:12
-
-
Save bearzk/c142755496f0f7d6e5cde00ee251c42a to your computer and use it in GitHub Desktop.
Stream to 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
async function streamToString(stream) { | |
return await new Promise((resolve, reject) => { | |
const chunks = []; | |
stream.on('data', (chunk) => chunks.push(chunk)); | |
stream.on('error', reject); | |
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8'))); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment