This commit is contained in:
Moon Man 2024-01-30 02:38:17 -05:00
parent 4fc40aa928
commit 6fb0cfe889
3 changed files with 4 additions and 14 deletions

2
dist/main.d.ts vendored
View File

@ -7,8 +7,6 @@ type ServerHandlerCallback = (reply: "reply" | "noreply", ...extraArgs: any[]) =
type ServerHandler = (term: any, from: any, state: any, callback: ServerHandlerCallback) => void; type ServerHandler = (term: any, from: any, state: any, callback: ServerHandlerCallback) => void;
export declare class Port extends Duplex { export declare class Port extends Duplex {
readonly bert: Bert; readonly bert: Bert;
private originalStdout;
private readonly fakeStdout;
constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean); constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean);
_read(): any; _read(): any;
_write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined): boolean; _write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined): boolean;

8
dist/main.js vendored
View File

@ -3,13 +3,9 @@ import { Duplex } from "node:stream";
const log = (msg) => process.stderr.write(`${msg}\r\n`); const log = (msg) => process.stderr.write(`${msg}\r\n`);
export class Port extends Duplex { export class Port extends Duplex {
bert; bert;
originalStdout;
fakeStdout = () => true;
constructor(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues) { constructor(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues) {
super({ objectMode: true }); super({ objectMode: true });
this.bert = new Bert(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues); this.bert = new Bert(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues);
this.originalStdout = process.stdout;
process.stdout.write = this.fakeStdout;
process.stdin.on("readable", () => { process.stdin.on("readable", () => {
while (this._read()) { } while (this._read()) { }
}); });
@ -39,8 +35,8 @@ export class Port extends Duplex {
const term = this.bert.encode(obj, true); const term = this.bert.encode(obj, true);
const len = Buffer.alloc(4); const len = Buffer.alloc(4);
len.writeUInt32BE(term.length, 0); len.writeUInt32BE(term.length, 0);
this.originalStdout.write(len); process.stdout.write(len);
this.originalStdout.write(term, actualCallback); process.stdout.write(term, actualCallback);
return true; return true;
} }
catch (error) { catch (error) {

View File

@ -10,14 +10,10 @@ const log = (msg: string) => process.stderr.write(`${msg}\r\n`);
export class Port extends Duplex { export class Port extends Duplex {
public readonly bert: Bert; public readonly bert: Bert;
private originalStdout;
private readonly fakeStdout = () => true;
constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean) { constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean) {
super({ objectMode: true }); super({ objectMode: true });
this.bert = new Bert(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues); this.bert = new Bert(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues);
this.originalStdout = process.stdout;
process.stdout.write = this.fakeStdout;
process.stdin.on("readable", () => { process.stdin.on("readable", () => {
while (this._read()) { } while (this._read()) { }
}); });
@ -51,8 +47,8 @@ export class Port extends Duplex {
const len = Buffer.alloc(4); const len = Buffer.alloc(4);
len.writeUInt32BE(term.length, 0); len.writeUInt32BE(term.length, 0);
this.originalStdout.write(len); process.stdout.write(len);
this.originalStdout.write(term, actualCallback); process.stdout.write(term, actualCallback);
return true; return true;
} }
catch (error) { catch (error) {