Skip to content

Instantly share code, notes, and snippets.

@bearzk
Created March 15, 2023 21:12
Show Gist options
  • Save bearzk/c142755496f0f7d6e5cde00ee251c42a to your computer and use it in GitHub Desktop.
Save bearzk/c142755496f0f7d6e5cde00ee251c42a to your computer and use it in GitHub Desktop.
Stream to string
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