Skip to content

Instantly share code, notes, and snippets.

@eschwartz
Created January 20, 2017 21:35
Show Gist options
  • Save eschwartz/d0e63381dbeec3f20d7fadc2fafd59f8 to your computer and use it in GitHub Desktop.
Save eschwartz/d0e63381dbeec3f20d7fadc2fafd59f8 to your computer and use it in GitHub Desktop.
Pipe a read-stream to a write-stream (promisifed)
import * as stream from 'stream';
function pipe(readStream:stream.Readable, writeStream: NodeJS.WritableStream):Promise<void> {
return new Promise<void>((onRes, onErr) => {
readStream
.on('error', onErr)
.pipe(writeStream)
.on('error', onErr)
.on('finish', () => onRes())
});
}
export default pipe;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment