Skip to content

Instantly share code, notes, and snippets.

@volkanozcan2

volkanozcan2/readable.js

Last active Aug 10, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.