mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
Re-enable basic stream support for fetch bodies (#3192)
* Add sd-streams from https://github.com/stardazed/sd-streams/blob/master/packages/streams/src/ * change the interfaces in dom_types to match what sd-streams expects
This commit is contained in:
parent
967c236fa5
commit
65d9286203
27 changed files with 5062 additions and 19 deletions
60
cli/js/streams/readable-stream-byob-request.ts
Normal file
60
cli/js/streams/readable-stream-byob-request.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Forked from https://github.com/stardazed/sd-streams/tree/8928cf04b035fd02fb1340b7eb541c76be37e546
|
||||
// Copyright (c) 2018-Present by Arthur Langereis - @zenmumbler MIT
|
||||
|
||||
/**
|
||||
* streams/readable-stream-byob-request - ReadableStreamBYOBRequest class implementation
|
||||
* Part of Stardazed
|
||||
* (c) 2018-Present by Arthur Langereis - @zenmumbler
|
||||
* https://github.com/stardazed/sd-streams
|
||||
*/
|
||||
|
||||
import * as rs from "./readable-internals.ts";
|
||||
|
||||
export class ReadableStreamBYOBRequest {
|
||||
[rs.associatedReadableByteStreamController_]:
|
||||
| rs.SDReadableByteStreamController
|
||||
| undefined;
|
||||
[rs.view_]: ArrayBufferView | undefined;
|
||||
|
||||
constructor() {
|
||||
throw new TypeError();
|
||||
}
|
||||
|
||||
get view(): ArrayBufferView {
|
||||
if (!rs.isReadableStreamBYOBRequest(this)) {
|
||||
throw new TypeError();
|
||||
}
|
||||
return this[rs.view_]!;
|
||||
}
|
||||
|
||||
respond(bytesWritten: number): void {
|
||||
if (!rs.isReadableStreamBYOBRequest(this)) {
|
||||
throw new TypeError();
|
||||
}
|
||||
if (this[rs.associatedReadableByteStreamController_] === undefined) {
|
||||
throw new TypeError();
|
||||
}
|
||||
// If! IsDetachedBuffer(this.[[view]].[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
|
||||
return rs.readableByteStreamControllerRespond(
|
||||
this[rs.associatedReadableByteStreamController_]!,
|
||||
bytesWritten
|
||||
);
|
||||
}
|
||||
|
||||
respondWithNewView(view: ArrayBufferView): void {
|
||||
if (!rs.isReadableStreamBYOBRequest(this)) {
|
||||
throw new TypeError();
|
||||
}
|
||||
if (this[rs.associatedReadableByteStreamController_] === undefined) {
|
||||
throw new TypeError();
|
||||
}
|
||||
if (!ArrayBuffer.isView(view)) {
|
||||
throw new TypeError("view parameter must be a TypedArray");
|
||||
}
|
||||
// If! IsDetachedBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception.
|
||||
return rs.readableByteStreamControllerRespondWithNewView(
|
||||
this[rs.associatedReadableByteStreamController_]!,
|
||||
view
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue