Skip to content

Instantly share code, notes, and snippets.

@nmccready
Created April 18, 2018 15:48
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 nmccready/2b8075b46de09dfb993940b2ab3f19f2 to your computer and use it in GitHub Desktop.
Save nmccready/2b8075b46de09dfb993940b2ab3f19f2 to your computer and use it in GitHub Desktop.
node streams utlities
const through = require('through2');
const debug = require('../../debug').spawn('logStream');
function logHandle(chunk, _, cb) {
const dbg = debug.spawn('logHandle');
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
dbg(() => JSON.stringify(chunk));
} else {
dbg(() => String(chunk));
}
this.push(chunk);
cb();
}
module.exports = function logStream() {
return through.obj(logHandle);
};
module.exports.logHandle = logHandle;
const { Readable } = require('stream');
module.exports = class StringStream extends Readable {
constructor(str) {
super();
this.push(str);
this.push(null);
}
_read() {}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment