Skip to content

Instantly share code, notes, and snippets.

@ischenkodv
Created March 18, 2017 21:54
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 ischenkodv/bcb5151e909c9db7502d3370937e7955 to your computer and use it in GitHub Desktop.
Save ischenkodv/bcb5151e909c9db7502d3370937e7955 to your computer and use it in GitHub Desktop.
Example of writable stream in NodeJS.
const stream = require('stream');
const fs = require('fs');
class EchoStream extends stream.Writable {
_write(chunk, enc, next) {
console.log(chunk.toString());
next();
}
}
const echoStream = new EchoStream();
fs.createReadStream('./test.txt').pipe(echoStream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment