summaryrefslogtreecommitdiff
path: root/cli/js/streams/readable-stream-byob-request.ts
diff options
context:
space:
mode:
authorNick Stott <nick@nickstott.com>2019-10-28 12:41:36 -0400
committerRy Dahl <ry@tinyclouds.org>2019-10-28 12:41:36 -0400
commit65d9286203cf239f68c6015818e82e8521e600a1 (patch)
tree0af1a7be449036f2f4ae9d3ecf06b7d645c8bddc /cli/js/streams/readable-stream-byob-request.ts
parent967c236fa5fb1e87e1b5ee788fe77d3a07361da1 (diff)
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
Diffstat (limited to 'cli/js/streams/readable-stream-byob-request.ts')
-rw-r--r--cli/js/streams/readable-stream-byob-request.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/cli/js/streams/readable-stream-byob-request.ts b/cli/js/streams/readable-stream-byob-request.ts
new file mode 100644
index 000000000..25b937f10
--- /dev/null
+++ b/cli/js/streams/readable-stream-byob-request.ts
@@ -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
+ );
+ }
+}