Files
scriptc/tests/corpus/1696-stream-read-inside-read.ts
2026-07-22 18:08:04 -05:00

26 lines
645 B
TypeScript

// this.push inside the read() option (the canonical generator shape): the
// read cb resolving `this` to the stream, refills continuing until
// push(null), and byte totals matching under flowing consumption.
import { Readable } from "node:stream";
let n = 0;
const r = new Readable({
highWaterMark: 4,
read() {
n++;
if (n <= 5) {
this.push(`c${n}`);
} else {
this.push(null);
}
},
});
let total = 0;
const order: string[] = [];
r.on("data", (chunk: Buffer) => {
total += chunk.length;
order.push(chunk.toString());
});
r.on("end", () => console.log("end:", total, order.join(",")));
console.log("tail");