Created
January 24, 2021 04:48
-
-
Save bbachi/c6465b83a06c9cd630aac91783ed0733 to your computer and use it in GitHub Desktop.
NodeJS Stream
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 { Writable } = require("stream"); | |
const myWritableStream = (data) => { | |
return new Writable({ | |
write(chunk, enc, next) { | |
data.push(chunk); | |
next(); | |
} | |
}) | |
} | |
const data = []; | |
const writable = myWritableStream(data); | |
writable.on('finish', () => { | |
console.log('Writing Done!!!', data.toString()); | |
}) | |
writable.write("This is the stream data 1\n"); | |
writable.write("This is the stream data 2\n"); | |
writable.write("This is the stream data 3\n"); | |
writable.end("Done!!!!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment