Files
scriptc/tests/fixtures/event-loop/stdio-readable-size.mjs
T
Chris Tate fb3806ce42 Search TypedArrays, read stdin through 'readable', and assign constructor-function globals
- TypedArray indexOf, lastIndexOf and includes on every element kind, typed
  and checked-dynamic: strict equality (SameValueZero for includes) and
  fromIndex as ToIntegerOrInfinity. A Buffer reached through a Uint8Array
  value keeps Buffer's search.
- process.stdin 'readable' with read() and read(size), including sizes
  above the read-ahead mark and input a once('readable') listener leaves
  for a later 'data' listener. for await over process.stdin yields Buffers.
- Module bindings holding `new F()` of a constructor function can be read
  and reassigned from other functions.
2026-10-23 03:54:26 -05:00

19 lines
467 B
JavaScript

// Fixed-size reads of stdin: read(n) answers null until n bytes are
// buffered, and the rest once the input ended.
const input = process.stdin;
const chunks = [];
const counts = [];
input.on('readable', () => {
let reads = 0;
let chunk;
while ((chunk = input.read(4)) !== null) {
chunks.push(chunk.toString('ascii'));
reads++;
}
counts.push(reads);
});
input.on('end', () => {
console.log(chunks.join('|'));
console.log(counts.join(','));
});