Skip to content

Commit 00efa5f

Browse files
committed
Add nodeFsync definition
1 parent 34fc32a commit 00efa5f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Platforms/emscripten/streams.mjs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const prepareBuffer = (buffer, offset, length) =>
112112

113113
const TTY_OPS = {
114114
ioctl_tiocgwinsz(tty) {
115-
return tty.devops.ioctl_tiocgwinsz();
115+
return tty.devops.ioctl_tiocgwinsz?.();
116116
},
117117
};
118118

@@ -146,6 +146,25 @@ const stream_ops = {
146146
},
147147
};
148148

149+
function nodeFsync(fd) {
150+
try {
151+
fs.fsyncSync(fd);
152+
} catch (e) {
153+
if (e?.code === "EINVAL") {
154+
return;
155+
}
156+
// On Mac, calling fsync when not isatty returns ENOTSUP
157+
// On Windows, stdin/stdout/stderr may be closed, returning EBADF or EPERM
158+
if (
159+
e?.code === "ENOTSUP" || e?.code === "EBADF" || e?.code === "EPERM"
160+
) {
161+
return;
162+
}
163+
164+
throw e;
165+
}
166+
}
167+
149168
class NodeReader {
150169
constructor(nodeStream) {
151170
this.nodeStream = nodeStream;
@@ -169,10 +188,6 @@ class NodeReader {
169188
fsync() {
170189
nodeFsync(this.nodeStream.fd);
171190
}
172-
173-
ioctl_tiocgwinsz() {
174-
return [this.nodeStream.columns ?? 24, this.nodeStream.rows ?? 80];
175-
}
176191
}
177192

178193
class NodeWriter {

0 commit comments

Comments
 (0)