Answer the question
In order to leave comments, you need to log in
Why does pipe keep reading from a Readable Stream if the buffer is full?
Good afternoon,
there
class MyReader extends Readable {
current = 0;
max = 100;
_read(size) {
this.current++;
if (this.current >= this.max) {
this.push(null);
} else {
const buffer = Buffer.from(`${this.current}`, 'utf8');
const couldBeAdded= this.push(buffer);
console.log(`push: ${this.current}, done: ${couldBeAdded}`);
}
}
}
class MyWriter extends Writable {
_write(chunk, encoding, done) {
setTimeout(() => {
console.log(`chunk: ${chunk.toString()}`);
done(); // торможу запись
}, 100);
}
}
const read = new MyReader({ highWaterMark: 4 });
const write = new MyWriter({ highWaterMark: 4 });
read.pipe(write);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question