Skip to content

Instantly share code, notes, and snippets.

@ortense
Created May 3, 2019 00:49
Show Gist options
  • Save ortense/473ce323d066fe608d99783965b0b17b to your computer and use it in GitHub Desktop.
Save ortense/473ce323d066fe608d99783965b0b17b to your computer and use it in GitHub Desktop.
Example of node stream API V3
import { promisify } from 'util'
import { pipeline } from 'stream'
import { createGzip } from 'zlib'
import { createReadStream, createWriteStream } from 'fs'
console.time('processing time')
promisify(pipeline)(
createReadStream('./big-file.iso'),
createGzip(),
createWriteStream('./big-file.tar.gz'))
.then(() => console.log('Done!'))
.catch(console.error)
.finally(() => console.timeEnd('processing time'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment