Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions types/whatwg-streams/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export interface ReadableStreamSource<R = ArrayBufferView> {
cancel?(reason: any): void | Promise<any>;
}

export interface ReadableByteStreamSource<R = ArrayBufferView> {
start?(controller: ReadableByteStreamController<R>): void | Promise<any>;
pull?(controller: ReadableByteStreamController<R>): void | Promise<any>;
export interface ReadableByteStreamSource {
start?(controller: ReadableByteStreamController): void | Promise<any>;
pull?(controller: ReadableByteStreamController): void | Promise<any>;
cancel?(reason: any): void | Promise<any>;

type: "bytes";
Expand All @@ -37,9 +37,14 @@ export interface WritableReadablePair<T extends WritableStream<any>, U extends R
readable: U;
}

export interface ReadResult<T> {
done: boolean;
value: T;
}

declare class ReadableStream<R = ArrayBufferView> {
constructor(underlyingSource?: ReadableStreamSource<R>, strategy?: QueuingStrategy<R>);
constructor(underlyingSource?: ReadableByteStreamSource<R>, strategy?: QueuingStrategy<R>);
constructor(underlyingSource?: ReadableByteStreamSource, strategy?: QueuingStrategy<R>);

readonly locked: boolean;

Expand All @@ -57,7 +62,7 @@ declare class ReadableStreamDefaultReader<R = ArrayBufferView> {
readonly closed: Promise<void>;

cancel(reason: any): Promise<void>;
read(): Promise<IteratorResult<R>>;
read(): Promise<ReadResult<R>>;
releaseLock(): void;
}

Expand All @@ -67,7 +72,7 @@ declare class ReadableStreamBYOBReader<R = ArrayBufferView> {
readonly closed: Promise<void>;

cancel(reason: any): Promise<void>;
read<T extends ArrayBufferView>(view: T): Promise<IteratorResult<T>>;
read<T extends ArrayBufferView>(view: T): Promise<ReadResult<T>>;
releaseLock(): void;
}

Expand All @@ -79,17 +84,17 @@ declare class ReadableStreamDefaultController<R = ArrayBufferView> {
error(e: any): void;
}

declare class ReadableByteStreamController<R = ArrayBufferView> {
readonly byobRequest: ReadableStreamBYOBRequest<R>;
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<R = ArrayBufferView> {
readonly view: R;
declare class ReadableStreamBYOBRequest {
readonly view: Uint8Array;

respond(bytesWritten: number): void;
respondWithNewView(view: ArrayBufferView): void;
Expand Down
4 changes: 2 additions & 2 deletions types/whatwg-streams/whatwg-streams-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <any>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);
}
});
},
Expand Down