Skip to content

Commit

Permalink
WIP: update highWaterMark value and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
PolarETech committed Jan 20, 2023
1 parent 997db02 commit fc94152
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions node/_process/streams.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,22 @@ export const stdout = stdio.stdout = createWritableStdioStream(
function _adjustHighWaterMark() {
if (Deno.isatty?.(Deno.stdin?.rid)) return 0;

if (Deno.build.os !== "windows") {
if (Deno.fstatSync(Deno.stdin?.rid).isFile) return 64 * 1024; // stdin is a redirected file
// TODO(PolarETech): Is there a better way to determine `/dev/null`.
if (Deno.fstatSync(Deno.stdin?.rid).mode === 8630) return 64 * 1024; // stdin is "ignore" (null)
return undefined; // stdin is "pipe" (stream)
}

// Avoid error that occurs when stdin is null on Windows.
try {
// TODO(PolarETech): On Windows, isFile() returns true even for a stream,
// TODO(PolarETech): On Windows, `Deno.fstatSync(rid).isFile` returns true even for a stream,
// so it cannot distinguish a stream from a file.
// When stdin is a stream, it should return `undefined` (= 16 * 1024), not 64 * 1024.
if (Deno.fstatSync(Deno.stdin?.rid).isFile) return 64 * 1024;
if (Deno.fstatSync(Deno.stdin?.rid).isFile) return 64 * 1024; // stdin is a redirected file
} catch (_) {
// Avoid error that occurs when stdin is null on Windows.
return 64 * 1024;
return 64 * 1024; // stdin is "ignore" (null)
}

// TODO(PolarETech): On Linux and Mac, 64 * 1024 should be returned when stdin is null.

return undefined;
}

/** https://nodejs.org/api/process.html#process_process_stdin */
Expand Down

0 comments on commit fc94152

Please sign in to comment.