UNPKG

lib-utils-ts

Version:

<img src="https://img.shields.io/npm/v/lib-utils-ts"/> <img src="https://img.shields.io/snyk/vulnerabilities/npm/lib-utils-ts"/> <img src="https://img.shields.io/npm/l/lib-utils-ts"/> <img src="https://img.shields.io/github/languages/top/devGnode/lib-util

25 lines (20 loc) 832 B
import {OutputStream} from "./OutputStream"; import {BYTE} from "../primitives/Globals"; import {ChildProcessWithoutNullStreams} from "child_process"; import {IOException} from "./IOException"; export class ProcessOutputStream extends OutputStream{ private readonly process:ChildProcessWithoutNullStreams; public constructor(p:ChildProcessWithoutNullStreams) { super(); this.process = p; } public write(b: number | BYTE | string | string[]): void { if(typeof b === "string"){ if(!(/(\r|\r\n|\n)$/).test(b)) b += "\r\n"; } try {this.process.stdin.write(b === "string" ? b.toString() : typeof b === "number" ? String.fromCharCode(b) : b.toString(), 'utf-8',(e)=>{});}catch (e) { throw new IOException(e.stack) } } } Object.package(this);