Last Updated: July 31, 2018
·
108
· martinhj

Handle Node streams with pipes and use events for user feedback

From Node.js Streams: Everything you need to know

const fs = require('fs');
const zlib = require('zlib');
const file = process.argv[2];

fs.createReadStream(file)
  .pipe(zlib.createGzip())
  .on('data', () => process.stdout.write('.'))
  .pipe(fs.createWriteStream(file + '.zz'))
  .on('finish', () => console.log('Done'));