MCPcopy Create free account
hub / github.com/BUPT-GAMMA/MASFactory / patchStream

Function patchStream

masfactory-visualizer/scripts/forceSyncStdio.cjs:3–24  ·  view source on GitHub ↗
(stream, fd)

Source from the content-addressed store, hash-verified

1const fs = require('fs');
2
3function patchStream(stream, fd) {
4 const originalWrite = stream.write.bind(stream);
5
6 stream.write = function write(chunk, encoding, callback) {
7 try {
8 if (typeof encoding === 'function') {
9 callback = encoding;
10 encoding = undefined;
11 }
12
13 const buffer = Buffer.isBuffer(chunk)
14 ? chunk
15 : Buffer.from(String(chunk), encoding || 'utf8');
16
17 fs.writeSync(fd, buffer);
18 if (typeof callback === 'function') callback();
19 return true;
20 } catch (error) {
21 return originalWrite(chunk, encoding, callback);
22 }
23 };
24}
25
26patchStream(process.stdout, 1);
27patchStream(process.stderr, 2);

Callers 1

forceSyncStdio.cjsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected