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