maybe works now?
This commit is contained in:
parent
f5f2341218
commit
a7535f4392
|
@ -4,8 +4,7 @@ import { Duplex } from "node:stream";
|
|||
type WriteCallback = (error: Error | null | undefined) => void;
|
||||
export declare class Port extends Duplex {
|
||||
constructor();
|
||||
read(): any;
|
||||
write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined): boolean;
|
||||
_final(): void;
|
||||
_read(): any;
|
||||
_write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined): boolean;
|
||||
}
|
||||
export {};
|
||||
|
|
|
@ -7,7 +7,7 @@ export class Port extends Duplex {
|
|||
constructor() {
|
||||
super({ objectMode: true });
|
||||
}
|
||||
read() {
|
||||
_read() {
|
||||
const lenBytes = process.stdin.read(4);
|
||||
if (lenBytes) {
|
||||
const termLen = bert.bytesToInt(lenBytes, 4, true);
|
||||
|
@ -23,7 +23,7 @@ export class Port extends Duplex {
|
|||
else
|
||||
return null;
|
||||
}
|
||||
write(obj, encodingOrCallback, callback) {
|
||||
_write(obj, encodingOrCallback, callback) {
|
||||
const actualCallback = callback || typeof encodingOrCallback === "function" ? encodingOrCallback : undefined;
|
||||
try {
|
||||
const term = bert.encode(obj, true);
|
||||
|
@ -37,8 +37,4 @@ export class Port extends Duplex {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
// When all the data is done passing, it stops.
|
||||
_final() {
|
||||
this.push(null);
|
||||
}
|
||||
}
|
||||
|
|
10
src/main.ts
10
src/main.ts
|
@ -13,7 +13,7 @@ export class Port extends Duplex {
|
|||
super({ objectMode: true });
|
||||
}
|
||||
|
||||
read() {
|
||||
_read() {
|
||||
const lenBytes = process.stdin.read(4);
|
||||
if (lenBytes) {
|
||||
const termLen = bert.bytesToInt(lenBytes, 4, true);
|
||||
|
@ -30,7 +30,7 @@ export class Port extends Duplex {
|
|||
else return null;
|
||||
}
|
||||
|
||||
write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined) {
|
||||
_write(obj: any, encodingOrCallback?: BufferEncoding | WriteCallback, callback?: WriteCallback | undefined) {
|
||||
const actualCallback: any = callback || typeof encodingOrCallback === "function" ? encodingOrCallback : undefined;
|
||||
|
||||
try {
|
||||
|
@ -46,10 +46,4 @@ export class Port extends Duplex {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// When all the data is done passing, it stops.
|
||||
_final() {
|
||||
this.push(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue