From b508e845671de9351c3f51755647371d76128d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 28 Apr 2020 12:32:43 +0200 Subject: [PATCH] refactor: remove combined io interface like ReadCloser (#4944) This commit removes "combined" interfaces from cli/js/io.ts; in the like of "ReadCloser", "WriteCloser" in favor of using intersections of concrete interfaces. --- cli/js/deno.ts | 7 ------- cli/js/io.ts | 18 ------------------ cli/js/lib.deno.ns.d.ts | 13 +++---------- cli/js/process.ts | 8 ++++---- cli/js/web/fetch.ts | 3 ++- 5 files changed, 9 insertions(+), 40 deletions(-) diff --git a/cli/js/deno.ts b/cli/js/deno.ts index 2efb6920ad..66ae5e176a 100644 --- a/cli/js/deno.ts +++ b/cli/js/deno.ts @@ -51,13 +51,6 @@ export { SyncWriter, Closer, Seeker, - SyncSeeker, - ReadCloser, - WriteCloser, - ReadSeeker, - WriteSeeker, - ReadWriteCloser, - ReadWriteSeeker, } from "./io.ts"; export { linkSync, link } from "./ops/fs/link.ts"; export { diff --git a/cli/js/io.ts b/cli/js/io.ts index ff7e092105..dace11c45f 100644 --- a/cli/js/io.ts +++ b/cli/js/io.ts @@ -52,24 +52,6 @@ export interface SyncSeeker { seekSync(offset: number, whence: SeekMode): number; } -// https://golang.org/pkg/io/#ReadCloser -export interface ReadCloser extends Reader, Closer {} - -// https://golang.org/pkg/io/#WriteCloser -export interface WriteCloser extends Writer, Closer {} - -// https://golang.org/pkg/io/#ReadSeeker -export interface ReadSeeker extends Reader, Seeker {} - -// https://golang.org/pkg/io/#WriteSeeker -export interface WriteSeeker extends Writer, Seeker {} - -// https://golang.org/pkg/io/#ReadWriteCloser -export interface ReadWriteCloser extends Reader, Writer, Closer {} - -// https://golang.org/pkg/io/#ReadWriteSeeker -export interface ReadWriteSeeker extends Reader, Writer, Seeker {} - export async function copy( src: Reader, dst: Writer, diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index 534c5707d1..4d06d07e4c 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -495,13 +495,6 @@ declare namespace Deno { seekSync(offset: number, whence: SeekMode): number; } - export interface ReadCloser extends Reader, Closer {} - export interface WriteCloser extends Writer, Closer {} - export interface ReadSeeker extends Reader, Seeker {} - export interface WriteSeeker extends Writer, Seeker {} - export interface ReadWriteCloser extends Reader, Writer, Closer {} - export interface ReadWriteSeeker extends Reader, Writer, Seeker {} - /** Copies from `src` to `dst` until either `EOF` is reached on `src` or an * error occurs. It resolves to the number of bytes copied or rejects with * the first error encountered while copying. @@ -2195,9 +2188,9 @@ declare namespace Deno { export class Process { readonly rid: number; readonly pid: number; - readonly stdin?: WriteCloser; - readonly stdout?: ReadCloser; - readonly stderr?: ReadCloser; + readonly stdin?: Writer & Closer; + readonly stdout?: Reader & Closer; + readonly stderr?: Reader & Closer; /** Resolves to the current status of the process. */ status(): Promise; /** Buffer the stdout and return it as `Uint8Array` after `Deno.EOF`. diff --git a/cli/js/process.ts b/cli/js/process.ts index c72fdef30d..c8627f86d6 100644 --- a/cli/js/process.ts +++ b/cli/js/process.ts @@ -1,7 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { File } from "./files.ts"; import { close } from "./ops/resources.ts"; -import { ReadCloser, WriteCloser } from "./io.ts"; +import { Closer, Reader, Writer } from "./io.ts"; import { readAll } from "./buffer.ts"; import { kill, runStatus as runStatusOp, run as runOp } from "./ops/process.ts"; @@ -33,9 +33,9 @@ async function runStatus(rid: number): Promise { export class Process { readonly rid: number; readonly pid: number; - readonly stdin?: WriteCloser; - readonly stdout?: ReadCloser; - readonly stderr?: ReadCloser; + readonly stdin?: Writer & Closer; + readonly stdout?: Reader & Closer; + readonly stderr?: Reader & Closer; // @internal constructor(res: RunResponse) { diff --git a/cli/js/web/fetch.ts b/cli/js/web/fetch.ts index abb5f2aa2d..60dafa1500 100644 --- a/cli/js/web/fetch.ts +++ b/cli/js/web/fetch.ts @@ -28,7 +28,8 @@ function hasHeaderValueOf(s: string, value: string): boolean { return new RegExp(`^${value}[\t\s]*;?`).test(s); } -class Body implements domTypes.Body, ReadableStream, io.ReadCloser { +class Body + implements domTypes.Body, ReadableStream, io.Reader, io.Closer { #bodyUsed = false; #bodyPromise: Promise | null = null; #data: ArrayBuffer | null = null;