node:readable stream
const { Readable } = require("stream"); | |
const { firstName, lastName } = require("faker/locale/en").name; | |
const { createWriteStream } = require("fs"); | |
class randomName extends Readable { | |
constructor(options) { | |
super(options); | |
this.count = 1e3; | |
} | |
_read() { | |
if (this.count > 0) { | |
this.push(`${firstName()} ${lastName()} \n`); | |
this.count--; | |
} | |
} | |
} | |
const foo = new randomName({ objectMode: true }); | |
const bar = createWriteStream("demo.txt"); | |
foo.pipe(bar); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment