diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-04-25 01:01:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-25 01:01:25 +0200 |
commit | 912a57f6a20c632c306f4e044df7618a3971abbf (patch) | |
tree | aa09526d214d2ab3f8d6e5c2baef605ba6d8a24a /cli/js/files.ts | |
parent | 4a8d25646aa58e3e59d622e69c41822b40415c46 (diff) |
change type of stdio handles in JS api (#4891)
Diffstat (limited to 'cli/js/files.ts')
-rw-r--r-- | cli/js/files.ts | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/cli/js/files.ts b/cli/js/files.ts index 97a8c1e2b..9b4738ba5 100644 --- a/cli/js/files.ts +++ b/cli/js/files.ts @@ -97,9 +97,66 @@ export class File } } -export const stdin = new File(0); -export const stdout = new File(1); -export const stderr = new File(2); +class Stdin implements Reader, SyncReader, Closer { + readonly rid: number; + constructor() { + this.rid = 0; + } + + read(p: Uint8Array): Promise<number | EOF> { + return read(this.rid, p); + } + + readSync(p: Uint8Array): number | EOF { + return readSync(this.rid, p); + } + + close(): void { + close(this.rid); + } +} + +class Stdout implements Writer, SyncWriter, Closer { + readonly rid: number; + constructor() { + this.rid = 1; + } + + write(p: Uint8Array): Promise<number> { + return write(this.rid, p); + } + + writeSync(p: Uint8Array): number { + return writeSync(this.rid, p); + } + + close(): void { + close(this.rid); + } +} + +export class Stderr implements Writer, SyncWriter, Closer { + readonly rid: number; + constructor() { + this.rid = 2; + } + + write(p: Uint8Array): Promise<number> { + return write(this.rid, p); + } + + writeSync(p: Uint8Array): number { + return writeSync(this.rid, p); + } + + close(): void { + close(this.rid); + } +} + +export const stdin = new Stdin(); +export const stdout = new Stdout(); +export const stderr = new Stderr(); function checkOpenOptions(options: OpenOptions): void { if (Object.values(options).filter((val) => val === true).length === 0) { |