diff options
Diffstat (limited to 'cli/js/web/body.ts')
-rw-r--r-- | cli/js/web/body.ts | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/cli/js/web/body.ts b/cli/js/web/body.ts index 717b02e29..a1cf2038a 100644 --- a/cli/js/web/body.ts +++ b/cli/js/web/body.ts @@ -1,25 +1,18 @@ import * as blob from "./blob.ts"; import * as encoding from "./text_encoding.ts"; import * as domTypes from "./dom_types.d.ts"; -import { ReadableStream } from "./streams/mod.ts"; +import { ReadableStreamImpl } from "./streams/readable_stream.ts"; // only namespace imports work for now, plucking out what we need const { TextEncoder, TextDecoder } = encoding; const DenoBlob = blob.DenoBlob; -type ReadableStreamReader = domTypes.ReadableStreamReader; - -interface ReadableStreamController { - enqueue(chunk: string | ArrayBuffer): void; - close(): void; -} - export type BodySource = | Blob | BufferSource | FormData | URLSearchParams - | domTypes.ReadableStream + | ReadableStream | string; function validateBodyType(owner: Body, bodySource: BodySource): boolean { @@ -39,7 +32,7 @@ function validateBodyType(owner: Body, bodySource: BodySource): boolean { return true; } else if (typeof bodySource === "string") { return true; - } else if (bodySource instanceof ReadableStream) { + } else if (bodySource instanceof ReadableStreamImpl) { return true; } else if (bodySource instanceof FormData) { return true; @@ -118,7 +111,7 @@ export const BodyUsedError = "Failed to execute 'clone' on 'Body': body is already used"; export class Body implements domTypes.Body { - protected _stream: domTypes.ReadableStream<string | ArrayBuffer> | null; + protected _stream: ReadableStreamImpl<string | ArrayBuffer> | null; constructor(protected _bodySource: BodySource, readonly contentType: string) { validateBodyType(this, _bodySource); @@ -127,23 +120,23 @@ export class Body implements domTypes.Body { this._stream = null; } - get body(): domTypes.ReadableStream | null { + get body(): ReadableStream | null { if (this._stream) { return this._stream; } - if (this._bodySource instanceof ReadableStream) { + if (this._bodySource instanceof ReadableStreamImpl) { // @ts-ignore this._stream = this._bodySource; } if (typeof this._bodySource === "string") { const bodySource = this._bodySource; - this._stream = new ReadableStream({ - start(controller: ReadableStreamController): void { + this._stream = new ReadableStreamImpl<string | ArrayBuffer>({ + start(controller: ReadableStreamDefaultController): void { controller.enqueue(bodySource); controller.close(); }, - }) as domTypes.ReadableStream<ArrayBuffer | string>; + }); } return this._stream; } @@ -320,7 +313,7 @@ export class Body implements domTypes.Body { return Promise.resolve( enc.encode(this._bodySource).buffer as ArrayBuffer ); - } else if (this._bodySource instanceof ReadableStream) { + } else if (this._bodySource instanceof ReadableStreamImpl) { // @ts-ignore return bufferFromStream(this._bodySource.getReader()); } else if (this._bodySource instanceof FormData) { |