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;
export declare class Port extends Duplex {
readonly bert: Bert;
private originalStdout;
private readonly fakeStdout;
constructor(allBinariesAsString?: boolean, mapKeyAsAtom?: boolean, decodeUndefinedValues?: boolean);
_read(): any;
_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`);
export class Port extends Duplex {
bert;
originalStdout;
fakeStdout = () => true;
constructor(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues) {
super({ objectMode: true });
this.bert = new Bert(allBinariesAsString, mapKeyAsAtom, decodeUndefinedValues);
this.originalStdout = process.stdout;
process.stdout.write = this.fakeStdout;
process.stdin.on("readable", () => {
while (this._read()) { }
});
@ -39,8 +35,8 @@ export class Port extends Duplex {
const term = this.bert.encode(obj, true);
const len = Buffer.alloc(4);
len.writeUInt32BE(term.length, 0);
this.originalStdout.write(len);
this.originalStdout.write(term, actualCallback);
process.stdout.write(len);
process.stdout.write(term, actualCallback);
return true;
}
catch (error) {

View File

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