Last active
April 28, 2023 10:42
-
-
Save Xunnamius/2a7f937cf10b800f22cb7986b090b22c to your computer and use it in GitHub Desktop.
Playing around with node streams and the stream-chain package
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
x = require('stream-json') | |
chain = require('stream-chain').chain | |
callbacks = []; | |
writable = new stream.Writable({ | |
objectMode: true, | |
write(c, _e, cb) { | |
console.log('_write'); | |
callbacks.push([c, cb]); | |
} | |
}); | |
writable.on('close', () => console.log('WRITABLE: close')); | |
writable.on('drain', () => console.log('WRITABLE: drain')); | |
writable.on('error', (error) => console.log('WRITABLE: error:', error)); | |
writable.on('finish', () => console.log('WRITABLE: finish')); | |
writable.on('pipe', () => console.log('WRITABLE: pipe')); | |
writable.on('unpipe', () => console.log('WRITABLE: unpipe')); | |
readable = new stream.Readable({ | |
objectMode: true, | |
read() { | |
console.log('_read'); | |
} | |
}); | |
readable.on('close', () => console.log('READABLE: close')); | |
readable.on('end', () => console.log('READABLE: end')); | |
readable.on('error', (error) => console.log('READABLE: error:', error)); | |
readable.on('pause', () => console.log('READABLE: pause')); | |
readable.on('resume', () => console.log('READABLE: resume')); | |
pipelineWritable = chain([writable], { allowHalfOpen: false, objectMode: true }); | |
pipelineWritable.on('close', () => console.log('PIPELINE-WRITABLE: close')); | |
pipelineWritable.on('drain', () => console.log('PIPELINE-WRITABLE: drain')); | |
pipelineWritable.on('error', (error) => | |
console.log('PIPELINE-WRITABLE: error:', error) | |
); | |
pipelineWritable.on('finish', () => console.log('PIPELINE-WRITABLE: finish')); | |
pipelineWritable.on('pipe', () => console.log('PIPELINE-WRITABLE: pipe')); | |
pipelineWritable.on('unpipe', () => console.log('PIPELINE-WRITABLE: unpipe')); | |
pipelineWritable.on('end', () => console.log('PIPELINE-WRITABLE: end')); | |
pipelineWritable.on('pause', () => console.log('PIPELINE-WRITABLE: pause')); | |
pipelineWritable.on('resume', () => console.log('PIPELINE-WRITABLE: resume')); | |
pipelineReadable = chain([readable], { allowHalfOpen: false, objectMode: true }); | |
pipelineReadable.on('close', () => console.log('PIPELINE-READABLE: close')); | |
pipelineReadable.on('drain', () => console.log('PIPELINE-READABLE: drain')); | |
pipelineReadable.on('error', (error) => | |
console.log('PIPELINE-READABLE: error:', error) | |
); | |
pipelineReadable.on('finish', () => console.log('PIPELINE-READABLE: finish')); | |
pipelineReadable.on('pipe', () => console.log('PIPELINE-READABLE: pipe')); | |
pipelineReadable.on('unpipe', () => console.log('PIPELINE-READABLE: unpipe')); | |
pipelineReadable.on('end', () => console.log('PIPELINE-READABLE: end')); | |
pipelineReadable.on('pause', () => console.log('PIPELINE-READABLE: pause')); | |
pipelineReadable.on('resume', () => console.log('PIPELINE-READABLE: resume')); | |
pipeline = chain([pipelineReadable, pipelineWritable], { allowHalfOpen: false, objectMode: true }); | |
pipeline.on('close', () => console.log('PIPELINE: close')); | |
pipeline.on('drain', () => console.log('PIPELINE: drain')); | |
pipeline.on('error', (error) => console.log('PIPELINE: error:', error)); | |
pipeline.on('finish', () => console.log('PIPELINE: finish')); | |
pipeline.on('pipe', () => console.log('PIPELINE: pipe')); | |
pipeline.on('unpipe', () => console.log('PIPELINE: unpipe')); | |
pipeline.on('end', () => console.log('PIPELINE: end')); | |
pipeline.on('pause', () => console.log('PIPELINE: pause')); | |
pipeline.on('resume', () => console.log('PIPELINE: resume')); | |
void undefined; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment