diff --git a/types/whatwg-streams/index.d.ts b/types/whatwg-streams/index.d.ts index 8b61b9d657..008029b2d9 100644 --- a/types/whatwg-streams/index.d.ts +++ b/types/whatwg-streams/index.d.ts @@ -12,9 +12,9 @@ export interface ReadableStreamSource { cancel?(reason: any): void | Promise; } -export interface ReadableByteStreamSource { - start?(controller: ReadableByteStreamController): void | Promise; - pull?(controller: ReadableByteStreamController): void | Promise; +export interface ReadableByteStreamSource { + start?(controller: ReadableByteStreamController): void | Promise; + pull?(controller: ReadableByteStreamController): void | Promise; cancel?(reason: any): void | Promise; type: "bytes"; @@ -37,9 +37,14 @@ export interface WritableReadablePair, U extends R readable: U; } +export interface ReadResult { + done: boolean; + value: T; +} + declare class ReadableStream { constructor(underlyingSource?: ReadableStreamSource, strategy?: QueuingStrategy); - constructor(underlyingSource?: ReadableByteStreamSource, strategy?: QueuingStrategy); + constructor(underlyingSource?: ReadableByteStreamSource, strategy?: QueuingStrategy); readonly locked: boolean; @@ -57,7 +62,7 @@ declare class ReadableStreamDefaultReader { readonly closed: Promise; cancel(reason: any): Promise; - read(): Promise>; + read(): Promise>; releaseLock(): void; } @@ -67,7 +72,7 @@ declare class ReadableStreamBYOBReader { readonly closed: Promise; cancel(reason: any): Promise; - read(view: T): Promise>; + read(view: T): Promise>; releaseLock(): void; } @@ -79,17 +84,17 @@ declare class ReadableStreamDefaultController { error(e: any): void; } -declare class ReadableByteStreamController { - readonly byobRequest: ReadableStreamBYOBRequest; +declare class ReadableByteStreamController { + readonly byobRequest: ReadableStreamBYOBRequest | undefined; readonly desiredSize: number | null; close(): void; - enqueue(chunk: R): void; + enqueue(chunk: ArrayBufferView): void; error(e: any): void; } -declare class ReadableStreamBYOBRequest { - readonly view: R; +declare class ReadableStreamBYOBRequest { + readonly view: Uint8Array; respond(bytesWritten: number): void; respondWithNewView(view: ArrayBufferView): void; diff --git a/types/whatwg-streams/whatwg-streams-tests.ts b/types/whatwg-streams/whatwg-streams-tests.ts index c6e83a89d3..be749686cc 100644 --- a/types/whatwg-streams/whatwg-streams-tests.ts +++ b/types/whatwg-streams/whatwg-streams-tests.ts @@ -187,14 +187,14 @@ function makeReadableByteFileStream(filename: string) { pull(controller: ReadableByteStreamController) { // Even when the consumer is using the default reader, the auto-allocation // feature allocates a buffer and passes it to us via byobRequest. - const v = controller.byobRequest.view; + const v = controller.byobRequest!.view; return fs.read(fd, v.buffer, v.byteOffset, v.byteLength, position).then(bytesRead => { if (bytesRead === 0) { return fs.close(fd).then(() => controller.close()); } else { position += bytesRead; - controller.byobRequest.respond(bytesRead); + controller.byobRequest!.respond(bytesRead); } }); },