Skip to content

Instantly share code, notes, and snippets.

@craigphicks
Created June 18, 2020 21:58
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 craigphicks/a5349d1267d501e6f008189446f8a59e to your computer and use it in GitHub Desktop.
Save craigphicks/a5349d1267d501e6f008189446f8a59e to your computer and use it in GitHub Desktop.
async function readStreamToEnd(rstream){
rstream.resume();
let prom=new Promise((resolve,reject)=>{
var buf = Buffer('');
rstream.on('data', function(newbuf) { buf=Buffer.concat([buf,newbuf]); });
rstream.on('end', function() { resolve(buf.toString()); });
rstream.on('error', function(e) { reject(e); });
});
return await prom;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment