Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add nodeFsync definition
  • Loading branch information
hoodmane committed Mar 30, 2026
commit 00efa5f4632d075ec4f70debb5741839e01e5ca7
25 changes: 20 additions & 5 deletions Platforms/emscripten/streams.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const prepareBuffer = (buffer, offset, length) =>

const TTY_OPS = {
ioctl_tiocgwinsz(tty) {
return tty.devops.ioctl_tiocgwinsz();
return tty.devops.ioctl_tiocgwinsz?.();
},
};

Expand Down Expand Up @@ -146,6 +146,25 @@ const stream_ops = {
},
};

function nodeFsync(fd) {
try {
fs.fsyncSync(fd);
} catch (e) {
if (e?.code === "EINVAL") {
return;
}
// On Mac, calling fsync when not isatty returns ENOTSUP
// On Windows, stdin/stdout/stderr may be closed, returning EBADF or EPERM
if (
e?.code === "ENOTSUP" || e?.code === "EBADF" || e?.code === "EPERM"
) {
return;
}

throw e;
}
}

class NodeReader {
constructor(nodeStream) {
this.nodeStream = nodeStream;
Expand All @@ -169,10 +188,6 @@ class NodeReader {
fsync() {
nodeFsync(this.nodeStream.fd);
}

ioctl_tiocgwinsz() {
return [this.nodeStream.columns ?? 24, this.nodeStream.rows ?? 80];
}
}

class NodeWriter {
Expand Down
Loading