Last active
September 17, 2020 07:35
-
-
Save PatrickHeneise/7a93158515a1c4d070128e5bff227397 to your computer and use it in GitHub Desktop.
stream transform
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 { PerformanceObserver, performance } = require('perf_hooks') | |
const getJSONParse = (data) => { | |
performance.mark('getJSONParse init') | |
JSON.parse(data) | |
performance.mark('getJSONParse end') | |
performance.measure('getJSONParse', 'getJSONParse init', 'getJSONParse end') | |
} |
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 { spawn } = require('child_process'); | |
const child = spawn('wc'); | |
process.stdin.pipe(child.stdin) | |
child.stdout.on('data', (data) => { | |
console.log(`child stdout:\n${data}`); | |
}); |
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 {Transform} = require('stream') | |
const transform = new Transform({ | |
transform(chunk, encoding, callback) { | |
this.push(chunk.toString().replace(/[1-9]/g,'*')) | |
callback() | |
} | |
}) | |
process.stdin.pipe(transform).pipe(process.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment