Created
April 18, 2018 15:48
-
-
Save nmccready/2b8075b46de09dfb993940b2ab3f19f2 to your computer and use it in GitHub Desktop.
node streams utlities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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