2023-02-26 01:30
This commit is contained in:
25
getting-started/21_stream.js
Normal file
25
getting-started/21_stream.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const fs = require('fs');
|
||||
const Stream = require('stream')
|
||||
|
||||
const readableStream = new Stream.Readable(
|
||||
{ read() { } }
|
||||
);
|
||||
const readableStream2 = fs.createReadStream('sample.txt');
|
||||
|
||||
const writableStream = new Stream.Writable(
|
||||
{
|
||||
write(chunk, encoding, next) {
|
||||
console.log(chunk.toString())
|
||||
next()
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
readableStream.pipe(writableStream);
|
||||
|
||||
readableStream.on('readable', () => {
|
||||
console.log(readableStream.read());
|
||||
});
|
||||
|
||||
writableStream.write('Hello...');
|
||||
writableStream.end();
|
||||
Reference in New Issue
Block a user