profile
viewpoint

push eventsuperfly/fly

Kurt

commit sha 8ca8e43882f3f48108031655a5023a284f6e26ab

feat: streaming responses

view details

Kurt

commit sha 92f426f2137577eaf439bd6bcf99c18ac0f28373

Handle ArrayBuffer stream writes

view details

Kurt

commit sha d8eae2531c7ea646ea96038a71c6185d7c3be74a

chore(release): v0.54.0-pre.0

view details

push time in 4 days

PR merged superfly/fly

feat: streaming responses
+295 -48

0 comment

29 changed files

mrkurt

pr closed time in 4 days

push eventsuperfly/fly

Kurt

commit sha d8eae2531c7ea646ea96038a71c6185d7c3be74a

chore(release): v0.54.0-pre.0

view details

push time in 4 days

created tagsuperfly/fly

tagv0.54.0-pre.0

Fly is a runtime for global applications. Use it to build CDNs, smart proxy applications, and be a little more geo-neutral.

created time in 4 days

push eventsuperfly/fly

Kurt

commit sha 8ca8e43882f3f48108031655a5023a284f6e26ab

feat: streaming responses

view details

Kurt

commit sha 92f426f2137577eaf439bd6bcf99c18ac0f28373

Handle ArrayBuffer stream writes

view details

push time in 4 days

push eventsuperfly/fly

Kurt

commit sha 607fc5d7b8a9e87705f66d51ce4c6ab95123885c

Handle ArrayBuffer stream writes

view details

push time in 4 days

push eventsuperfly/fly

Michael Dwan

commit sha 4a4eaa897d25f3ae0f4e88c4ab846e1a0529c67b

Remove rustproxy shim

view details

Michael Dwan

commit sha 3deaee6a9b16abc2176bf19c0fef682afface62e

chore(release): v0.53.0

view details

Michael Dwan

commit sha 38e7a42e34aebee07277bd8c9ee5bf58972a0586

bump lerna to get the new graduate command

view details

Michael Dwan

commit sha fda2bdce24382373a0574c2744452493e84e5d04

fix: tests not found if entry set in webpack config

view details

Michael Dwan

commit sha 651083f792edfd860ad318ab33841b93ab6aff4b

Merge pull request #238 from superfly/remove-rustproxy-shim Remove rustproxy shim

view details

Michael Dwan

commit sha 9d66f843b5c125eeea4044213011fab58a1bb4bf

chore(release): v0.53.1-pre.0

view details

Michael Dwan

commit sha 7696fa58a636e8866c405b74422c17494c3959c9

chore(release): v0.53.1

view details

Kurt

commit sha 2533a4a6488fd98e3eceecd88c32c4b928dd981e

feat: streaming responses

view details

push time in 4 days

PR opened superfly/fly

feat: streaming responses
+163 -8

0 comment

11 changed files

pr created time in 4 days

create barnchsuperfly/fly

branch : response-streams

created branch time in 4 days

created tagsuperfly/edge

tagv0.9.0-2

A set of useful libraries for Edge Apps. Run locally, write tests, and integrate it into your deployment process. Move fast and maybe don't break things? Because, gosh darnit, you're an adult.

created time in 7 days

push eventsuperfly/edge

Kurt

commit sha 33110fd70b275175c5af83634a1652c1e854924e

ugh

view details

push time in 7 days

created tagsuperfly/edge

tagv0.9.0-1

A set of useful libraries for Edge Apps. Run locally, write tests, and integrate it into your deployment process. Move fast and maybe don't break things? Because, gosh darnit, you're an adult.

created time in 7 days

push eventsuperfly/edge

Kurt

commit sha 80ad11c2f11c8badbf96adcee84f4df2a39f952a

chore(release): 0.9.0-1

view details

push time in 7 days

push eventsuperfly/edge

Kurt

commit sha 3a9115795268b28b95dfb411184585986ac23cd5

fix: bad response on data API DELETE

view details

push time in 7 days

issue openeddenoland/deno

Stream request bodies to fetch

This was discussed/planned in #522.

We need this (and related http stuff) because we work with proxies quite a lot. A common pattern is:

  • fetch a file of some kind
  • clone response
  • fetch to post one of the clones to a cache
  • Send other clone to end user

We also get people doing things like multiplexing s3 uploads, similar problem there.

created time in 10 days

push eventsuperfly/edge

Kurt

commit sha c0d50c4b548d02da3527ad2b7c48ee86d1aac869

chore(release): 0.9.0-0

view details

push time in 11 days

created tagsuperfly/edge

tagv0.9.0-0

A set of useful libraries for Edge Apps. Run locally, write tests, and integrate it into your deployment process. Move fast and maybe don't break things? Because, gosh darnit, you're an adult.

created time in 11 days

push eventsuperfly/edge

Kurt

commit sha fd4e6e44bbc41aa042278f56887c07fe5f137798

disable github workflow

view details

push time in 11 days

push eventsuperfly/edge

Kurt

commit sha 8ea1f5bf4a1a3e8431f1dc9b7e17079919a1c6fd

bump ci node version

view details

push time in 11 days

push eventsuperfly/edge

Kurt

commit sha 5a8ccf88fb1e7d447a632f057f7736e3cc4bafad

feat: data store REST API + write through cache Expose a REST API for managing data in a Fly app's k/v store: ```typescript import { data } from "@fly/edge" const api = restAPI({authToken: "aSeCUrToken", basePath: "/__data/"}); fly.http.respondWith(req => { const url = new URL(req.url); if(url.pathname.startsWith("/__data/")){ return api(req); } return new Response('not found', { status: 404}); }) ```

view details

push time in 11 days

push eventsuperfly/fly

Kurt

commit sha b48ba6f637c8498df3e6b447f825e8801a218ea5

chore(release): v0.52.1-pre.0

view details

push time in 14 days

created tagsuperfly/fly

tagv0.52.1-pre.0

Fly is a runtime for global applications. Use it to build CDNs, smart proxy applications, and be a little more geo-neutral.

created time in 14 days

push eventsuperfly/fly

Kurt

commit sha 4bf7db39b026b629c4d6baf7f951274ae528c2b5

feat: content-encoding=skip header bypasses gzip, clears header

view details

push time in 14 days

PR opened denoland/deno

fix body formData tests

cleanup for tests disabled in #2268

+9 -3

0 comment

1 changed file

pr created time in 18 days

create barnchsuperfly/deno

branch : body-test-fix

created branch time in 18 days

issue openeddenoland/deno

fetch tests not running?

I don't think fetch_test.ts is running properly, it seems like all the tests defined with testPerm are getting ignored. None of them even show up in the appveyor logs.

image

created time in 19 days

pull request commentdenoland/deno

Global request / response

@ry Lint is passing now! Appveyor is not loving that submodule conflict though.

mrkurt

comment created time in 19 days

push eventsuperfly/deno

Kurt

commit sha 542ff88252cf0ef9430e34b63932f6d10ae18a4a

tests + cleanup on Response type

view details

push time in 19 days

push eventsuperfly/deno

Kurt

commit sha c5a305519dcab004d312d977fd395aa1c5e44385

tests + cleanup on Response type

view details

push time in 19 days

Pull request review commentdenoland/deno

Global request / response

+/**+* @stardazed/streams - implementation of the web streams standard+* Part of Stardazed+* (c) 2018-Present by Arthur Langereis - @zenmumbler+* https://github.com/stardazed/sd-streams+*/++const state_ = Symbol("state_");+const storedError_ = Symbol("storedError_");+function isInteger(value) {+    if (!isFinite(value)) {+        return false;+    }+    const absValue = Math.abs(value);+    return Math.floor(absValue) === absValue;+}+function isFiniteNonNegativeNumber(value) {+    if (!(typeof value === "number" && isFinite(value))) {+        return false;+    }+    return value >= 0;+}+function isAbortSignal(signal) {+    if (typeof signal !== "object" || signal === null) {+        return false;+    }+    try {+        const aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, "aborted").get;+        aborted.call(signal);+        return true;+    }+    catch (err) {+        return false;+    }+}+function invokeOrNoop(o, p, args) {+    const method = o[p];+    if (method === undefined) {+        return undefined;+    }+    return Function.prototype.apply.call(method, o, args);+}+function cloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, cloneConstructor) {+    return srcBuffer.slice(srcByteOffset, srcByteOffset + srcLength);+}+function transferArrayBuffer(buffer) {+    return buffer.slice(0);+}+function copyDataBlockBytes(toBlock, toIndex, fromBlock, fromIndex, count) {+    new Uint8Array(toBlock, toIndex, count).set(new Uint8Array(fromBlock, fromIndex, count));+}+const objectCloneMemo = new WeakMap();+let sharedArrayBufferSupported_;+function supportsSharedArrayBuffer() {+    if (sharedArrayBufferSupported_ === undefined) {+        try {+            new SharedArrayBuffer(16);+            sharedArrayBufferSupported_ = true;+        }+        catch (e) {+            sharedArrayBufferSupported_ = false;+        }+    }+    return sharedArrayBufferSupported_;+}+function cloneValue(value) {+    const valueType = typeof value;+    switch (valueType) {+        case "number":+        case "string":+        case "boolean":+        case "undefined":+        case "bigint":+            return value;+        case "object": {+            if (objectCloneMemo.has(value)) {+                return objectCloneMemo.get(value);+            }+            if (value === null) {+                return value;+            }+            if (value instanceof Date) {+                return new Date(value.valueOf());+            }+            if (value instanceof RegExp) {+                return new RegExp(value);+            }+            if (supportsSharedArrayBuffer() && value instanceof SharedArrayBuffer) {+                return value;+            }+            if (value instanceof ArrayBuffer) {+                const cloned = cloneArrayBuffer(value, 0, value.byteLength, ArrayBuffer);+                objectCloneMemo.set(value, cloned);+                return cloned;+            }+            if (ArrayBuffer.isView(value)) {+                const clonedBuffer = cloneValue(value.buffer);+                let length;+                if (value instanceof DataView) {+                    length = value.byteLength;+                }+                else {+                    length = value.length;+                }+                return new value.constructor(clonedBuffer, value.byteOffset, length);+            }+            if (value instanceof Map) {+                const clonedMap = new Map();+                objectCloneMemo.set(value, clonedMap);+                value.forEach((v, k) => clonedMap.set(k, cloneValue(v)));+                return clonedMap;+            }+            if (value instanceof Set) {+                const clonedSet = new Map();+                objectCloneMemo.set(value, clonedSet);+                value.forEach((v, k) => clonedSet.set(k, cloneValue(v)));+                return clonedSet;+            }+            const clonedObj = {};+            objectCloneMemo.set(value, clonedObj);+            const sourceKeys = Object.getOwnPropertyNames(value);+            for (const key of sourceKeys) {+                clonedObj[key] = cloneValue(value[key]);+            }+            return clonedObj;+        }+        case "symbol":+        case "function":+        default:+            throw new DOMException("Uncloneable value in stream", "DataCloneError");+    }+}+function promiseCall(f, v, args) {+    try {+        const result = Function.prototype.apply.call(f, v, args);+        return Promise.resolve(result);+    }+    catch (err) {+        return Promise.reject(err);+    }+}+function createAlgorithmFromUnderlyingMethod(obj, methodName, extraArgs) {+    const method = obj[methodName];+    if (method === undefined) {+        return () => Promise.resolve(undefined);+    }+    if (typeof method !== "function") {+        throw new TypeError(`Field "${methodName}" is not a function.`);+    }+    return function (...fnArgs) {+        return promiseCall(method, obj, fnArgs.concat(extraArgs));+    };+}+function validateAndNormalizeHighWaterMark(hwm) {+    const highWaterMark = Number(hwm);+    if (isNaN(highWaterMark) || highWaterMark < 0) {+        throw new RangeError("highWaterMark must be a valid, non-negative integer.");+    }+    return highWaterMark;+}+function makeSizeAlgorithmFromSizeFunction(sizeFn) {+    if (typeof sizeFn !== "function" && typeof sizeFn !== "undefined") {+        throw new TypeError("size function must be undefined or a function");+    }+    return function (chunk) {+        if (typeof sizeFn === "function") {+            return sizeFn(chunk);+        }+        return 1;+    };+}+var ControlledPromiseState;+(function (ControlledPromiseState) {+    ControlledPromiseState[ControlledPromiseState["Pending"] = 0] = "Pending";+    ControlledPromiseState[ControlledPromiseState["Resolved"] = 1] = "Resolved";+    ControlledPromiseState[ControlledPromiseState["Rejected"] = 2] = "Rejected";+})(ControlledPromiseState || (ControlledPromiseState = {}));+function createControlledPromise() {+    const conProm = {+        state: ControlledPromiseState.Pending+    };+    conProm.promise = new Promise(function (resolve, reject) {+        conProm.resolve = function (v) { conProm.state = ControlledPromiseState.Resolved; resolve(v); };+        conProm.reject = function (e) { conProm.state = ControlledPromiseState.Rejected; reject(e); };+    });+    return conProm;+}++const CHUNK_SIZE = 16384;+class QueueImpl {+    constructor() {+        this.chunks_ = [[]];+        this.readChunk_ = this.writeChunk_ = this.chunks_[0];+        this.length_ = 0;+    }+    push(t) {+        this.writeChunk_.push(t);+        this.length_ += 1;+        if (this.writeChunk_.length === CHUNK_SIZE) {+            this.writeChunk_ = [];+            this.chunks_.push(this.writeChunk_);+        }+    }+    front() {+        if (this.length_ === 0) {+            return undefined;+        }+        return this.readChunk_[0];+    }+    shift() {+        if (this.length_ === 0) {+            return undefined;+        }+        const t = this.readChunk_.shift();+        this.length_ -= 1;+        if (this.readChunk_.length === 0 && this.readChunk_ !== this.writeChunk_) {+            this.chunks_.shift();+            this.readChunk_ = this.chunks_[0];+        }+        return t;+    }+    get length() {+        return this.length_;+    }+}++const queue_ = Symbol("queue_");+const queueTotalSize_ = Symbol("queueTotalSize_");+function dequeueValue(container) {+    const pair = container[queue_].shift();+    const newTotalSize = container[queueTotalSize_] - pair.size;+    container[queueTotalSize_] = Math.max(0, newTotalSize);+    return pair.value;+}+function enqueueValueWithSize(container, value, size) {+    if (!isFiniteNonNegativeNumber(size)) {+        throw new RangeError("Chunk size must be a non-negative, finite numbers");+    }+    container[queue_].push({ value, size });+    container[queueTotalSize_] += size;+}+function peekQueueValue(container) {+    return container[queue_].front().value;+}+function resetQueue(container) {+    container[queue_] = new QueueImpl();+    container[queueTotalSize_] = 0;+}++const controlledReadableStream_ = Symbol("controlledReadableStream_");+const pullAlgorithm_ = Symbol("pullAlgorithm_");+const cancelAlgorithm_ = Symbol("cancelAlgorithm_");+const strategySizeAlgorithm_ = Symbol("strategySizeAlgorithm_");+const strategyHWM_ = Symbol("strategyHWM_");+const started_ = Symbol("started_");+const closeRequested_ = Symbol("closeRequested_");+const pullAgain_ = Symbol("pullAgain_");+const pulling_ = Symbol("pulling_");+const cancelSteps_ = Symbol("cancelSteps_");+const pullSteps_ = Symbol("pullSteps_");+const autoAllocateChunkSize_ = Symbol("autoAllocateChunkSize_");+const byobRequest_ = Symbol("byobRequest_");+const controlledReadableByteStream_ = Symbol("controlledReadableByteStream_");+const pendingPullIntos_ = Symbol("pendingPullIntos_");+const closedPromise_ = Symbol("closedPromise_");+const ownerReadableStream_ = Symbol("ownerReadableStream_");+const readRequests_ = Symbol("readRequests_");+const readIntoRequests_ = Symbol("readIntoRequests_");+const associatedReadableByteStreamController_ = Symbol("associatedReadableByteStreamController_");+const view_ = Symbol("view_");+const reader_ = Symbol("reader_");+const readableStreamController_ = Symbol("readableStreamController_");+function initializeReadableStream(stream) {+    stream[state_] = "readable";+    stream[reader_] = undefined;+    stream[storedError_] = undefined;+    stream[readableStreamController_] = undefined;+}+function isReadableStream(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return readableStreamController_ in value;+}+function isReadableStreamLocked(stream) {+    return stream[reader_] !== undefined;+}+function readableStreamGetNumReadIntoRequests(stream) {+    const reader = stream[reader_];+    if (reader === undefined) {+        return 0;+    }+    return reader[readIntoRequests_].length;+}+function readableStreamGetNumReadRequests(stream) {+    const reader = stream[reader_];+    if (reader === undefined) {+        return 0;+    }+    return reader[readRequests_].length;+}+function readableStreamCreateReadResult(value, done, forAuthorCode) {+    const prototype = forAuthorCode ? Object.prototype : null;+    const result = Object.create(prototype);+    result.value = value;+    result.done = done;+    return result;+}+function readableStreamAddReadIntoRequest(stream, forAuthorCode) {+    const reader = stream[reader_];+    const conProm = createControlledPromise();+    conProm.forAuthorCode = forAuthorCode;+    reader[readIntoRequests_].push(conProm);+    return conProm.promise;+}+function readableStreamAddReadRequest(stream, forAuthorCode) {+    const reader = stream[reader_];+    const conProm = createControlledPromise();+    conProm.forAuthorCode = forAuthorCode;+    reader[readRequests_].push(conProm);+    return conProm.promise;+}+function readableStreamHasBYOBReader(stream) {+    const reader = stream[reader_];+    return isReadableStreamBYOBReader(reader);+}+function readableStreamHasDefaultReader(stream) {+    const reader = stream[reader_];+    return isReadableStreamDefaultReader(reader);+}+function readableStreamCancel(stream, reason) {+    if (stream[state_] === "closed") {+        return Promise.resolve(undefined);+    }+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    readableStreamClose(stream);+    const sourceCancelPromise = stream[readableStreamController_][cancelSteps_](reason);+    return sourceCancelPromise.then(_ => undefined);+}+function readableStreamClose(stream) {+    stream[state_] = "closed";+    const reader = stream[reader_];+    if (reader === undefined) {+        return;+    }+    if (isReadableStreamDefaultReader(reader)) {+        for (const readRequest of reader[readRequests_]) {+            readRequest.resolve(readableStreamCreateReadResult(undefined, true, readRequest.forAuthorCode));+        }+        reader[readRequests_] = [];+    }+    reader[closedPromise_].resolve();+    reader[closedPromise_].promise.catch(() => { });+}+function readableStreamError(stream, error) {+    if (stream[state_] !== "readable") {+        throw new RangeError("Stream is in an invalid state");+    }+    stream[state_] = "errored";+    stream[storedError_] = error;+    const reader = stream[reader_];+    if (reader === undefined) {+        return;+    }+    if (isReadableStreamDefaultReader(reader)) {+        for (const readRequest of reader[readRequests_]) {+            readRequest.reject(error);+        }+        reader[readRequests_] = [];+    }+    else {+        const readIntoRequests = reader[readIntoRequests_];+        for (const readIntoRequest of readIntoRequests) {+            readIntoRequest.reject(error);+        }+        reader[readIntoRequests_] = [];+    }+    reader[closedPromise_].reject(error);+}+function isReadableStreamDefaultReader(reader) {+    if (typeof reader !== "object" || reader === null) {+        return false;+    }+    return readRequests_ in reader;+}+function isReadableStreamBYOBReader(reader) {+    if (typeof reader !== "object" || reader === null) {+        return false;+    }+    return readIntoRequests_ in reader;+}+function readableStreamReaderGenericInitialize(reader, stream) {+    reader[ownerReadableStream_] = stream;+    stream[reader_] = reader;+    const streamState = stream[state_];+    reader[closedPromise_] = createControlledPromise();+    if (streamState === "readable") ;+    else if (streamState === "closed") {+        reader[closedPromise_].resolve(undefined);+    }+    else {+        reader[closedPromise_].reject(stream[storedError_]);+        reader[closedPromise_].promise.catch(() => { });+    }+}+function readableStreamReaderGenericRelease(reader) {+    const stream = reader[ownerReadableStream_];+    if (stream === undefined) {+        throw new TypeError("Reader is in an inconsistent state");+    }+    if (stream[state_] === "readable") ;+    else {+        reader[closedPromise_] = createControlledPromise();+    }+    reader[closedPromise_].reject(new TypeError());+    reader[closedPromise_].promise.catch(() => { });+    stream[reader_] = undefined;+    reader[ownerReadableStream_] = undefined;+}+function readableStreamBYOBReaderRead(reader, view, forAuthorCode = false) {+    const stream = reader[ownerReadableStream_];+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return readableByteStreamControllerPullInto(stream[readableStreamController_], view, forAuthorCode);+}+function readableStreamDefaultReaderRead(reader, forAuthorCode = false) {+    const stream = reader[ownerReadableStream_];+    if (stream[state_] === "closed") {+        return Promise.resolve(readableStreamCreateReadResult(undefined, true, forAuthorCode));+    }+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return stream[readableStreamController_][pullSteps_](forAuthorCode);+}+function readableStreamFulfillReadIntoRequest(stream, chunk, done) {+    const reader = stream[reader_];+    const readIntoRequest = reader[readIntoRequests_].shift();+    readIntoRequest.resolve(readableStreamCreateReadResult(chunk, done, readIntoRequest.forAuthorCode));+}+function readableStreamFulfillReadRequest(stream, chunk, done) {+    const reader = stream[reader_];+    const readRequest = reader[readRequests_].shift();+    readRequest.resolve(readableStreamCreateReadResult(chunk, done, readRequest.forAuthorCode));+}+function setUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {+    controller[controlledReadableStream_] = stream;+    resetQueue(controller);+    controller[started_] = false;+    controller[closeRequested_] = false;+    controller[pullAgain_] = false;+    controller[pulling_] = false;+    controller[strategySizeAlgorithm_] = sizeAlgorithm;+    controller[strategyHWM_] = highWaterMark;+    controller[pullAlgorithm_] = pullAlgorithm;+    controller[cancelAlgorithm_] = cancelAlgorithm;+    stream[readableStreamController_] = controller;+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_] = true;+        readableStreamDefaultControllerCallPullIfNeeded(controller);+    }, error => {+        readableStreamDefaultControllerError(controller, error);+    });+}+function isReadableStreamDefaultController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledReadableStream_ in value;+}+function readableStreamDefaultControllerHasBackpressure(controller) {+    return !readableStreamDefaultControllerShouldCallPull(controller);+}+function readableStreamDefaultControllerCanCloseOrEnqueue(controller) {+    const state = controller[controlledReadableStream_][state_];+    return controller[closeRequested_] === false && state === "readable";+}+function readableStreamDefaultControllerGetDesiredSize(controller) {+    const state = controller[controlledReadableStream_][state_];+    if (state === "errored") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return controller[strategyHWM_] - controller[queueTotalSize_];+}+function readableStreamDefaultControllerClose(controller) {+    controller[closeRequested_] = true;+    const stream = controller[controlledReadableStream_];+    if (controller[queue_].length === 0) {+        readableStreamDefaultControllerClearAlgorithms(controller);+        readableStreamClose(stream);+    }+}+function readableStreamDefaultControllerEnqueue(controller, chunk) {+    const stream = controller[controlledReadableStream_];+    if (isReadableStreamLocked(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        readableStreamFulfillReadRequest(stream, chunk, false);+    }+    else {+        let chunkSize;+        try {+            chunkSize = controller[strategySizeAlgorithm_](chunk);+        }+        catch (error) {+            readableStreamDefaultControllerError(controller, error);+            throw error;+        }+        try {+            enqueueValueWithSize(controller, chunk, chunkSize);+        }+        catch (error) {+            readableStreamDefaultControllerError(controller, error);+            throw error;+        }+    }+    readableStreamDefaultControllerCallPullIfNeeded(controller);+}+function readableStreamDefaultControllerError(controller, error) {+    const stream = controller[controlledReadableStream_];+    if (stream[state_] !== "readable") {+        return;+    }+    resetQueue(controller);+    readableStreamDefaultControllerClearAlgorithms(controller);+    readableStreamError(stream, error);+}+function readableStreamDefaultControllerCallPullIfNeeded(controller) {+    if (!readableStreamDefaultControllerShouldCallPull(controller)) {+        return;+    }+    if (controller[pulling_]) {+        controller[pullAgain_] = true;+        return;+    }+    if (controller[pullAgain_]) {+        throw new RangeError("Stream controller is in an invalid state.");+    }+    controller[pulling_] = true;+    controller[pullAlgorithm_](controller).then(_ => {+        controller[pulling_] = false;+        if (controller[pullAgain_]) {+            controller[pullAgain_] = false;+            readableStreamDefaultControllerCallPullIfNeeded(controller);+        }+    }, error => {+        readableStreamDefaultControllerError(controller, error);+    });+}+function readableStreamDefaultControllerShouldCallPull(controller) {+    const stream = controller[controlledReadableStream_];+    if (!readableStreamDefaultControllerCanCloseOrEnqueue(controller)) {+        return false;+    }+    if (controller[started_] === false) {+        return false;+    }+    if (isReadableStreamLocked(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        return true;+    }+    const desiredSize = readableStreamDefaultControllerGetDesiredSize(controller);+    if (desiredSize === null) {+        throw new RangeError("Stream is in an invalid state.");+    }+    return desiredSize > 0;+}+function readableStreamDefaultControllerClearAlgorithms(controller) {+    controller[pullAlgorithm_] = undefined;+    controller[cancelAlgorithm_] = undefined;+    controller[strategySizeAlgorithm_] = undefined;+}+function setUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {+    if (stream[readableStreamController_] !== undefined) {+        throw new TypeError("Cannot reuse streams");+    }+    if (autoAllocateChunkSize !== undefined) {+        if (!isInteger(autoAllocateChunkSize) || autoAllocateChunkSize <= 0) {+            throw new RangeError("autoAllocateChunkSize must be a positive, finite integer");+        }+    }+    controller[controlledReadableByteStream_] = stream;+    controller[pullAgain_] = false;+    controller[pulling_] = false;+    readableByteStreamControllerClearPendingPullIntos(controller);+    resetQueue(controller);+    controller[closeRequested_] = false;+    controller[started_] = false;+    controller[strategyHWM_] = validateAndNormalizeHighWaterMark(highWaterMark);+    controller[pullAlgorithm_] = pullAlgorithm;+    controller[cancelAlgorithm_] = cancelAlgorithm;+    controller[autoAllocateChunkSize_] = autoAllocateChunkSize;+    controller[pendingPullIntos_] = [];+    stream[readableStreamController_] = controller;+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_] = true;+        readableByteStreamControllerCallPullIfNeeded(controller);+    }, error => {+        readableByteStreamControllerError(controller, error);+    });+}+function isReadableStreamBYOBRequest(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return associatedReadableByteStreamController_ in value;+}+function isReadableByteStreamController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledReadableByteStream_ in value;+}+function readableByteStreamControllerCallPullIfNeeded(controller) {+    if (!readableByteStreamControllerShouldCallPull(controller)) {+        return;+    }+    if (controller[pulling_]) {+        controller[pullAgain_] = true;+        return;+    }+    controller[pulling_] = true;+    controller[pullAlgorithm_](controller).then(_ => {+        controller[pulling_] = false;+        if (controller[pullAgain_]) {+            controller[pullAgain_] = false;+            readableByteStreamControllerCallPullIfNeeded(controller);+        }+    }, error => {+        readableByteStreamControllerError(controller, error);+    });+}+function readableByteStreamControllerClearAlgorithms(controller) {+    controller[pullAlgorithm_] = undefined;+    controller[cancelAlgorithm_] = undefined;+}+function readableByteStreamControllerClearPendingPullIntos(controller) {+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    controller[pendingPullIntos_] = [];+}+function readableByteStreamControllerClose(controller) {+    const stream = controller[controlledReadableByteStream_];+    if (controller[queueTotalSize_] > 0) {+        controller[closeRequested_] = true;+        return;+    }+    if (controller[pendingPullIntos_].length > 0) {+        const firstPendingPullInto = controller[pendingPullIntos_][0];+        if (firstPendingPullInto.bytesFilled > 0) {+            const error = new TypeError();+            readableByteStreamControllerError(controller, error);+            throw error;+        }+    }+    readableByteStreamControllerClearAlgorithms(controller);+    readableStreamClose(stream);+}+function readableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {+    let done = false;+    if (stream[state_] === "closed") {+        done = true;+    }+    const filledView = readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);+    if (pullIntoDescriptor.readerType === "default") {+        readableStreamFulfillReadRequest(stream, filledView, done);+    }+    else {+        readableStreamFulfillReadIntoRequest(stream, filledView, done);+    }+}+function readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {+    const { bytesFilled, elementSize } = pullIntoDescriptor;+    return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);+}+function readableByteStreamControllerEnqueue(controller, chunk) {+    const stream = controller[controlledReadableByteStream_];+    const { buffer, byteOffset, byteLength } = chunk;+    const transferredBuffer = transferArrayBuffer(buffer);+    if (readableStreamHasDefaultReader(stream)) {+        if (readableStreamGetNumReadRequests(stream) === 0) {+            readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+        }+        else {+            const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);+            readableStreamFulfillReadRequest(stream, transferredView, false);+        }+    }+    else if (readableStreamHasBYOBReader(stream)) {+        readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+        readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);+    }+    else {+        readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+    }+    readableByteStreamControllerCallPullIfNeeded(controller);+}+function readableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {+    controller[queue_].push({ buffer, byteOffset, byteLength });+    controller[queueTotalSize_] += byteLength;+}+function readableByteStreamControllerError(controller, error) {+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] !== "readable") {+        return;+    }+    readableByteStreamControllerClearPendingPullIntos(controller);+    resetQueue(controller);+    readableByteStreamControllerClearAlgorithms(controller);+    readableStreamError(stream, error);+}+function readableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    pullIntoDescriptor.bytesFilled += size;+}+function readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {+    const elementSize = pullIntoDescriptor.elementSize;+    const currentAlignedBytes = pullIntoDescriptor.bytesFilled - (pullIntoDescriptor.bytesFilled % elementSize);+    const maxBytesToCopy = Math.min(controller[queueTotalSize_], pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);+    const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;+    const maxAlignedBytes = maxBytesFilled - (maxBytesFilled % elementSize);+    let totalBytesToCopyRemaining = maxBytesToCopy;+    let ready = false;+    if (maxAlignedBytes > currentAlignedBytes) {+        totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;+        ready = true;+    }+    const queue = controller[queue_];+    while (totalBytesToCopyRemaining > 0) {+        const headOfQueue = queue.front();+        const bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);+        const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;+        copyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);+        if (headOfQueue.byteLength === bytesToCopy) {+            queue.shift();+        }+        else {+            headOfQueue.byteOffset += bytesToCopy;+            headOfQueue.byteLength -= bytesToCopy;+        }+        controller[queueTotalSize_] -= bytesToCopy;+        readableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);+        totalBytesToCopyRemaining -= bytesToCopy;+    }+    return ready;+}+function readableByteStreamControllerGetDesiredSize(controller) {+    const stream = controller[controlledReadableByteStream_];+    const state = stream[state_];+    if (state === "errored") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return controller[strategyHWM_] - controller[queueTotalSize_];+}+function readableByteStreamControllerHandleQueueDrain(controller) {+    if (controller[queueTotalSize_] === 0 && controller[closeRequested_]) {+        readableByteStreamControllerClearAlgorithms(controller);+        readableStreamClose(controller[controlledReadableByteStream_]);+    }+    else {+        readableByteStreamControllerCallPullIfNeeded(controller);+    }+}+function readableByteStreamControllerInvalidateBYOBRequest(controller) {+    const byobRequest = controller[byobRequest_];+    if (byobRequest === undefined) {+        return;+    }+    byobRequest[associatedReadableByteStreamController_] = undefined;+    byobRequest[view_] = undefined;+    controller[byobRequest_] = undefined;+}+function readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {+    const pendingPullIntos = controller[pendingPullIntos_];+    while (pendingPullIntos.length > 0) {+        if (controller[queueTotalSize_] === 0) {+            return;+        }+        const pullIntoDescriptor = pendingPullIntos[0];+        if (readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {+            readableByteStreamControllerShiftPendingPullInto(controller);+            readableByteStreamControllerCommitPullIntoDescriptor(controller[controlledReadableByteStream_], pullIntoDescriptor);+        }+    }+}+function readableByteStreamControllerPullInto(controller, view, forAuthorCode) {+    const stream = controller[controlledReadableByteStream_];+    const elementSize = view.BYTES_PER_ELEMENT || 1;+    const ctor = view.constructor;+    const byteOffset = view.byteOffset;+    const byteLength = view.byteLength;+    const buffer = transferArrayBuffer(view.buffer);+    const pullIntoDescriptor = { buffer, byteOffset, byteLength, bytesFilled: 0, elementSize, ctor, readerType: "byob" };+    if (controller[pendingPullIntos_].length > 0) {+        controller[pendingPullIntos_].push(pullIntoDescriptor);+        return readableStreamAddReadIntoRequest(stream, forAuthorCode);+    }+    if (stream[state_] === "closed") {+        const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);+        return Promise.resolve(readableStreamCreateReadResult(emptyView, true, forAuthorCode));+    }+    if (controller[queueTotalSize_] > 0) {+        if (readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {+            const filledView = readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);+            readableByteStreamControllerHandleQueueDrain(controller);+            return Promise.resolve(readableStreamCreateReadResult(filledView, false, forAuthorCode));+        }+        if (controller[closeRequested_]) {+            const error = new TypeError();+            readableByteStreamControllerError(controller, error);+            return Promise.reject(error);+        }+    }+    controller[pendingPullIntos_].push(pullIntoDescriptor);+    const promise = readableStreamAddReadIntoRequest(stream, forAuthorCode);+    readableByteStreamControllerCallPullIfNeeded(controller);+    return promise;+}+function readableByteStreamControllerRespond(controller, bytesWritten) {+    bytesWritten = Number(bytesWritten);+    if (!isFiniteNonNegativeNumber(bytesWritten)) {+        throw new RangeError("bytesWritten must be a finite, non-negative number");+    }+    readableByteStreamControllerRespondInternal(controller, bytesWritten);+}+function readableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {+    firstDescriptor.buffer = transferArrayBuffer(firstDescriptor.buffer);+    const stream = controller[controlledReadableByteStream_];+    if (readableStreamHasBYOBReader(stream)) {+        while (readableStreamGetNumReadIntoRequests(stream) > 0) {+            const pullIntoDescriptor = readableByteStreamControllerShiftPendingPullInto(controller);+            readableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);+        }+    }+}+function readableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {+    if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {+        throw new RangeError();+    }+    readableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);+    if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {+        return;+    }+    readableByteStreamControllerShiftPendingPullInto(controller);+    const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;+    if (remainderSize > 0) {+        const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;+        const remainder = cloneArrayBuffer(pullIntoDescriptor.buffer, end - remainderSize, remainderSize, ArrayBuffer);+        readableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);+    }+    pullIntoDescriptor.buffer = transferArrayBuffer(pullIntoDescriptor.buffer);+    pullIntoDescriptor.bytesFilled = pullIntoDescriptor.bytesFilled - remainderSize;+    readableByteStreamControllerCommitPullIntoDescriptor(controller[controlledReadableByteStream_], pullIntoDescriptor);+    readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);+}+function readableByteStreamControllerRespondInternal(controller, bytesWritten) {+    const firstDescriptor = controller[pendingPullIntos_][0];+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] === "closed") {+        if (bytesWritten !== 0) {+            throw new TypeError();+        }+        readableByteStreamControllerRespondInClosedState(controller, firstDescriptor);+    }+    else {+        readableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);+    }+    readableByteStreamControllerCallPullIfNeeded(controller);+}+function readableByteStreamControllerRespondWithNewView(controller, view) {+    const firstDescriptor = controller[pendingPullIntos_][0];+    if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {+        throw new RangeError();+    }+    if (firstDescriptor.byteLength !== view.byteLength) {+        throw new RangeError();+    }+    firstDescriptor.buffer = view.buffer;+    readableByteStreamControllerRespondInternal(controller, view.byteLength);+}+function readableByteStreamControllerShiftPendingPullInto(controller) {+    const descriptor = controller[pendingPullIntos_].shift();+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    return descriptor;+}+function readableByteStreamControllerShouldCallPull(controller) {+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] !== "readable") {+        return false;+    }+    if (controller[closeRequested_]) {+        return false;+    }+    if (!controller[started_]) {+        return false;+    }+    if (readableStreamHasDefaultReader(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        return true;+    }+    if (readableStreamHasBYOBReader(stream) && readableStreamGetNumReadIntoRequests(stream) > 0) {+        return true;+    }+    const desiredSize = readableByteStreamControllerGetDesiredSize(controller);+    return desiredSize > 0;+}+function setUpReadableStreamBYOBRequest(request, controller, view) {+    if (!isReadableByteStreamController(controller)) {+        throw new TypeError();+    }+    if (!ArrayBuffer.isView(view)) {+        throw new TypeError();+    }+    request[associatedReadableByteStreamController_] = controller;+    request[view_] = view;+}++const backpressure_ = Symbol("backpressure_");+const closeRequest_ = Symbol("closeRequest_");+const inFlightWriteRequest_ = Symbol("inFlightWriteRequest_");+const inFlightCloseRequest_ = Symbol("inFlightCloseRequest_");+const pendingAbortRequest_ = Symbol("pendingAbortRequest_");+const writableStreamController_ = Symbol("writableStreamController_");+const writer_ = Symbol("writer_");+const writeRequests_ = Symbol("writeRequests_");+const abortAlgorithm_ = Symbol("abortAlgorithm_");+const closeAlgorithm_ = Symbol("closeAlgorithm_");+const controlledWritableStream_ = Symbol("controlledWritableStream_");+const started_$1 = Symbol("started_");+const strategyHWM_$1 = Symbol("strategyHWM_");+const strategySizeAlgorithm_$1 = Symbol("strategySizeAlgorithm_");+const writeAlgorithm_ = Symbol("writeAlgorithm_");+const ownerWritableStream_ = Symbol("ownerWritableStream_");+const closedPromise_$1 = Symbol("closedPromise_");+const readyPromise_ = Symbol("readyPromise_");+const errorSteps_ = Symbol("errorSteps_");+const abortSteps_ = Symbol("abortSteps_");+function initializeWritableStream(stream) {+    stream[state_] = "writable";+    stream[storedError_] = undefined;+    stream[writer_] = undefined;+    stream[writableStreamController_] = undefined;+    stream[inFlightWriteRequest_] = undefined;+    stream[closeRequest_] = undefined;+    stream[inFlightCloseRequest_] = undefined;+    stream[pendingAbortRequest_] = undefined;+    stream[writeRequests_] = [];+    stream[backpressure_] = false;+}+function isWritableStream(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return writableStreamController_ in value;+}+function isWritableStreamLocked(stream) {+    return stream[writer_] !== undefined;+}+function writableStreamAbort(stream, reason) {+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return Promise.resolve(undefined);+    }+    let pending = stream[pendingAbortRequest_];+    if (pending !== undefined) {+        return pending.promise;+    }+    let wasAlreadyErroring = false;+    if (state === "erroring") {+        wasAlreadyErroring = true;+        reason = undefined;+    }+    pending = {+        reason,+        wasAlreadyErroring+    };+    const promise = new Promise((resolve, reject) => {+        pending.resolve = resolve;+        pending.reject = reject;+    });+    pending.promise = promise;+    stream[pendingAbortRequest_] = pending;+    if (!wasAlreadyErroring) {+        writableStreamStartErroring(stream, reason);+    }+    return promise;+}+function writableStreamAddWriteRequest(stream) {+    const writePromise = createControlledPromise();+    stream[writeRequests_].push(writePromise);+    return writePromise.promise;+}+function writableStreamDealWithRejection(stream, error) {+    const state = stream[state_];+    if (state === "writable") {+        writableStreamStartErroring(stream, error);+        return;+    }+    writableStreamFinishErroring(stream);+}+function writableStreamStartErroring(stream, reason) {+    const controller = stream[writableStreamController_];+    stream[state_] = "erroring";+    stream[storedError_] = reason;+    const writer = stream[writer_];+    if (writer !== undefined) {+        writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);+    }+    if (!writableStreamHasOperationMarkedInFlight(stream) && controller[started_$1]) {+        writableStreamFinishErroring(stream);+    }+}+function writableStreamFinishErroring(stream) {+    stream[state_] = "errored";+    const controller = stream[writableStreamController_];+    controller[errorSteps_]();+    const storedError = stream[storedError_];+    for (const writeRequest of stream[writeRequests_]) {+        writeRequest.reject(storedError);+    }+    stream[writeRequests_] = [];+    const abortRequest = stream[pendingAbortRequest_];+    if (abortRequest === undefined) {+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+        return;+    }+    stream[pendingAbortRequest_] = undefined;+    if (abortRequest.wasAlreadyErroring) {+        abortRequest.reject(storedError);+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+        return;+    }+    const promise = controller[abortSteps_](abortRequest.reason);+    promise.then(_ => {+        abortRequest.resolve();+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+    }, error => {+        abortRequest.reject(error);+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+    });+}+function writableStreamFinishInFlightWrite(stream) {+    stream[inFlightWriteRequest_].resolve(undefined);+    stream[inFlightWriteRequest_] = undefined;+}+function writableStreamFinishInFlightWriteWithError(stream, error) {+    stream[inFlightWriteRequest_].reject(error);+    stream[inFlightWriteRequest_] = undefined;+    writableStreamDealWithRejection(stream, error);+}+function writableStreamFinishInFlightClose(stream) {+    stream[inFlightCloseRequest_].resolve(undefined);+    stream[inFlightCloseRequest_] = undefined;+    const state = stream[state_];+    if (state === "erroring") {+        stream[storedError_] = undefined;+        if (stream[pendingAbortRequest_] !== undefined) {+            stream[pendingAbortRequest_].resolve();+            stream[pendingAbortRequest_] = undefined;+        }+    }+    stream[state_] = "closed";+    const writer = stream[writer_];+    if (writer !== undefined) {+        writer[closedPromise_$1].resolve(undefined);+    }+}+function writableStreamFinishInFlightCloseWithError(stream, error) {+    stream[inFlightCloseRequest_].reject(error);+    stream[inFlightCloseRequest_] = undefined;+    if (stream[pendingAbortRequest_] !== undefined) {+        stream[pendingAbortRequest_].reject(error);+        stream[pendingAbortRequest_] = undefined;+    }+    writableStreamDealWithRejection(stream, error);+}+function writableStreamCloseQueuedOrInFlight(stream) {+    return (stream[closeRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined);+}+function writableStreamHasOperationMarkedInFlight(stream) {+    return stream[inFlightWriteRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined;+}+function writableStreamMarkCloseRequestInFlight(stream) {+    stream[inFlightCloseRequest_] = stream[closeRequest_];+    stream[closeRequest_] = undefined;+}+function writableStreamMarkFirstWriteRequestInFlight(stream) {+    const writeRequest = stream[writeRequests_].shift();+    stream[inFlightWriteRequest_] = writeRequest;+}+function writableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {+    const closeRequest = stream[closeRequest_];+    if (closeRequest !== undefined) {+        closeRequest.reject(stream[storedError_]);+        stream[closeRequest_] = undefined;+    }+    const writer = stream[writer_];+    if (writer !== undefined) {+        writer[closedPromise_$1].reject(stream[storedError_]);+        writer[closedPromise_$1].promise.catch(() => { });+    }+}+function writableStreamUpdateBackpressure(stream, backpressure) {+    const writer = stream[writer_];+    if (writer !== undefined && backpressure !== stream[backpressure_]) {+        if (backpressure) {+            writer[readyPromise_] = createControlledPromise();+        }+        else {+            writer[readyPromise_].resolve(undefined);+        }+    }+    stream[backpressure_] = backpressure;+}+function isWritableStreamDefaultWriter(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return ownerWritableStream_ in value;+}+function writableStreamDefaultWriterAbort(writer, reason) {+    const stream = writer[ownerWritableStream_];+    return writableStreamAbort(stream, reason);+}+function writableStreamDefaultWriterClose(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return Promise.reject(new TypeError("Writer stream is already closed or errored"));+    }+    const closePromise = createControlledPromise();+    stream[closeRequest_] = closePromise;+    if (stream[backpressure_] && state === "writable") {+        writer[readyPromise_].resolve(undefined);+    }+    writableStreamDefaultControllerClose(stream[writableStreamController_]);+    return closePromise.promise;+}+function writableStreamDefaultWriterCloseWithErrorPropagation(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") {+        return Promise.resolve(undefined);+    }+    if (state === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return writableStreamDefaultWriterClose(writer);+}+function writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {+    const closedPromise = writer[closedPromise_$1];+    if (closedPromise.state === ControlledPromiseState.Pending) {+        closedPromise.reject(error);+    }+    else {+        writer[closedPromise_$1] = createControlledPromise();+        writer[closedPromise_$1].reject(error);+    }+    writer[closedPromise_$1].promise.catch(() => { });+}+function writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {+    const readyPromise = writer[readyPromise_];+    if (readyPromise.state === ControlledPromiseState.Pending) {+        readyPromise.reject(error);+    }+    else {+        writer[readyPromise_] = createControlledPromise();+        writer[readyPromise_].reject(error);+    }+    writer[readyPromise_].promise.catch(() => { });+}+function writableStreamDefaultWriterGetDesiredSize(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (state === "errored" || state === "erroring") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return writableStreamDefaultControllerGetDesiredSize(stream[writableStreamController_]);+}+function writableStreamDefaultWriterRelease(writer) {+    const stream = writer[ownerWritableStream_];+    const releasedError = new TypeError();+    writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);+    writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);+    stream[writer_] = undefined;+    writer[ownerWritableStream_] = undefined;+}+function writableStreamDefaultWriterWrite(writer, chunk) {+    const stream = writer[ownerWritableStream_];+    const controller = stream[writableStreamController_];+    const chunkSize = writableStreamDefaultControllerGetChunkSize(controller, chunk);+    if (writer[ownerWritableStream_] !== stream) {+        return Promise.reject(new TypeError());+    }+    const state = stream[state_];+    if (state === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") {+        return Promise.reject(new TypeError("Cannot write to a closing or closed stream"));+    }+    if (state === "erroring") {+        return Promise.reject(stream[storedError_]);+    }+    const promise = writableStreamAddWriteRequest(stream);+    writableStreamDefaultControllerWrite(controller, chunk, chunkSize);+    return promise;+}+function setUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {+    if (!isWritableStream(stream)) {+        throw new TypeError();+    }+    if (stream[writableStreamController_] !== undefined) {+        throw new TypeError();+    }+    controller[controlledWritableStream_] = stream;+    stream[writableStreamController_] = controller;+    resetQueue(controller);+    controller[started_$1] = false;+    controller[strategySizeAlgorithm_$1] = sizeAlgorithm;+    controller[strategyHWM_$1] = highWaterMark;+    controller[writeAlgorithm_] = writeAlgorithm;+    controller[closeAlgorithm_] = closeAlgorithm;+    controller[abortAlgorithm_] = abortAlgorithm;+    const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+    writableStreamUpdateBackpressure(stream, backpressure);+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_$1] = true;+        writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+    }, error => {+        controller[started_$1] = true;+        writableStreamDealWithRejection(stream, error);+    });+}+function isWritableStreamDefaultController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledWritableStream_ in value;+}+function writableStreamDefaultControllerClearAlgorithms(controller) {+    controller[writeAlgorithm_] = undefined;+    controller[closeAlgorithm_] = undefined;+    controller[abortAlgorithm_] = undefined;+    controller[strategySizeAlgorithm_$1] = undefined;+}+function writableStreamDefaultControllerClose(controller) {+    enqueueValueWithSize(controller, "close", 0);+    writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+}+function writableStreamDefaultControllerGetChunkSize(controller, chunk) {+    let chunkSize;+    try {+        chunkSize = controller[strategySizeAlgorithm_$1](chunk);+    }+    catch (error) {+        writableStreamDefaultControllerErrorIfNeeded(controller, error);+        chunkSize = 1;+    }+    return chunkSize;+}+function writableStreamDefaultControllerGetDesiredSize(controller) {+    return controller[strategyHWM_$1] - controller[queueTotalSize_];+}+function writableStreamDefaultControllerWrite(controller, chunk, chunkSize) {+    try {+        enqueueValueWithSize(controller, { chunk }, chunkSize);+    }+    catch (error) {+        writableStreamDefaultControllerErrorIfNeeded(controller, error);+        return;+    }+    const stream = controller[controlledWritableStream_];+    if (!writableStreamCloseQueuedOrInFlight(stream) && stream[state_] === "writable") {+        const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+        writableStreamUpdateBackpressure(stream, backpressure);+    }+    writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+}+function writableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {+    if (!controller[started_$1]) {+        return;+    }+    const stream = controller[controlledWritableStream_];+    if (stream[inFlightWriteRequest_] !== undefined) {+        return;+    }+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return;+    }+    if (state === "erroring") {+        writableStreamFinishErroring(stream);+        return;+    }+    if (controller[queue_].length === 0) {+        return;+    }+    const writeRecord = peekQueueValue(controller);+    if (writeRecord === "close") {+        writableStreamDefaultControllerProcessClose(controller);+    }+    else {+        writableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk);+    }+}+function writableStreamDefaultControllerErrorIfNeeded(controller, error) {+    if (controller[controlledWritableStream_][state_] === "writable") {+        writableStreamDefaultControllerError(controller, error);+    }+}+function writableStreamDefaultControllerProcessClose(controller) {+    const stream = controller[controlledWritableStream_];+    writableStreamMarkCloseRequestInFlight(stream);+    dequeueValue(controller);+    const sinkClosePromise = controller[closeAlgorithm_]();+    writableStreamDefaultControllerClearAlgorithms(controller);+    sinkClosePromise.then(_ => {+        writableStreamFinishInFlightClose(stream);+    }, error => {+        writableStreamFinishInFlightCloseWithError(stream, error);+    });+}+function writableStreamDefaultControllerProcessWrite(controller, chunk) {+    const stream = controller[controlledWritableStream_];+    writableStreamMarkFirstWriteRequestInFlight(stream);+    controller[writeAlgorithm_](chunk).then(_ => {+        writableStreamFinishInFlightWrite(stream);+        const state = stream[state_];+        dequeueValue(controller);+        if (!writableStreamCloseQueuedOrInFlight(stream) && state === "writable") {+            const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+            writableStreamUpdateBackpressure(stream, backpressure);+        }+        writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+    }, error => {+        if (stream[state_] === "writable") {+            writableStreamDefaultControllerClearAlgorithms(controller);+        }+        writableStreamFinishInFlightWriteWithError(stream, error);+    });+}+function writableStreamDefaultControllerGetBackpressure(controller) {+    const desiredSize = writableStreamDefaultControllerGetDesiredSize(controller);+    return desiredSize <= 0;+}+function writableStreamDefaultControllerError(controller, error) {+    const stream = controller[controlledWritableStream_];+    writableStreamDefaultControllerClearAlgorithms(controller);+    writableStreamStartErroring(stream, error);+}++class ReadableStreamDefaultReader {+    constructor(stream) {+        if (!isReadableStream(stream)) {+            throw new TypeError();+        }+        if (isReadableStreamLocked(stream)) {+            throw new TypeError("The stream is locked.");+        }+        readableStreamReaderGenericInitialize(this, stream);+        this[readRequests_] = [];+    }+    get closed() {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        return this[closedPromise_].promise;+    }+    cancel(reason) {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        const stream = this[ownerReadableStream_];+        if (stream === undefined) {+            return Promise.reject(new TypeError("Reader is not associated with a stream"));+        }+        return readableStreamCancel(stream, reason);+    }+    read() {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerReadableStream_] === undefined) {+            return Promise.reject(new TypeError("Reader is not associated with a stream"));+        }+        return readableStreamDefaultReaderRead(this, true);+    }+    releaseLock() {+        if (!isReadableStreamDefaultReader(this)) {+            throw new TypeError();+        }+        if (this[ownerReadableStream_] === undefined) {+            return;+        }+        if (this[readRequests_].length !== 0) {+            throw new TypeError("Cannot release a stream with pending read requests");+        }+        readableStreamReaderGenericRelease(this);+    }+}++class WritableStreamDefaultWriter {+    constructor(stream) {+        if (!isWritableStream(stream)) {+            throw new TypeError();+        }+        if (isWritableStreamLocked(stream)) {+            throw new TypeError("Stream is already locked");+        }+        this[ownerWritableStream_] = stream;+        stream[writer_] = this;+        const readyPromise = createControlledPromise();+        const closedPromise = createControlledPromise();+        this[readyPromise_] = readyPromise;+        this[closedPromise_$1] = closedPromise;+        const state = stream[state_];+        if (state === "writable") {+            if (!writableStreamCloseQueuedOrInFlight(stream) && stream[backpressure_]) ;+            else {+                readyPromise.resolve(undefined);+            }+        }+        else if (state === "erroring") {+            readyPromise.reject(stream[storedError_]);+            readyPromise.promise.catch(() => { });+        }+        else if (state === "closed") {+            readyPromise.resolve(undefined);+            closedPromise.resolve(undefined);+        }+        else {+            const storedError = stream[storedError_];+            readyPromise.reject(storedError);+            readyPromise.promise.catch(() => { });+            closedPromise.reject(storedError);+            closedPromise.promise.catch(() => { });+        }+    }+    abort(reason) {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerWritableStream_] === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        return writableStreamDefaultWriterAbort(this, reason);+    }+    close() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        const stream = this[ownerWritableStream_];+        if (stream === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        if (writableStreamCloseQueuedOrInFlight(stream)) {+            return Promise.reject(new TypeError());+        }+        return writableStreamDefaultWriterClose(this);+    }+    releaseLock() {+        const stream = this[ownerWritableStream_];+        if (stream === undefined) {+            return;+        }+        writableStreamDefaultWriterRelease(this);+    }+    write(chunk) {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerWritableStream_] === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        return writableStreamDefaultWriterWrite(this, chunk);+    }+    get closed() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        return this[closedPromise_$1].promise;+    }+    get desiredSize() {+        if (!isWritableStreamDefaultWriter(this)) {+            throw new TypeError();+        }+        if (this[ownerWritableStream_] === undefined) {+            throw new TypeError("Writer is not connected to stream");+        }+        return writableStreamDefaultWriterGetDesiredSize(this);+    }+    get ready() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        return this[readyPromise_].promise;+    }+}++function pipeTo(source, dest, options) {+    const preventClose = !!options.preventClose;+    const preventAbort = !!options.preventAbort;+    const preventCancel = !!options.preventCancel;+    const signal = options.signal;+    let shuttingDown = false;+    let latestWrite = Promise.resolve();+    const promise = createControlledPromise();+    const reader = new ReadableStreamDefaultReader(source);+    const writer = new WritableStreamDefaultWriter(dest);+    let abortAlgorithm;+    if (signal !== undefined) {+        abortAlgorithm = () => {+            const error = new DOMException("Aborted", "AbortError");+            const actions = [];+            if (preventAbort === false) {+                actions.push(() => {+                    if (dest[state_] === "writable") {+                        return writableStreamAbort(dest, error);+                    }+                    return Promise.resolve();+                });+            }+            if (preventCancel === false) {+                actions.push(() => {+                    if (source[state_] === "readable") {+                        return readableStreamCancel(source, error);+                    }+                    return Promise.resolve();+                });+            }+            shutDown(() => {+                return Promise.all(actions.map(a => a())).then(_ => undefined);+            }, { actualError: error });+        };+        if (signal.aborted === true) {+            abortAlgorithm();+        }+        else {+            signal.addEventListener("abort", abortAlgorithm);+        }+    }+    function onStreamErrored(stream, promise, action) {+        if (stream[state_] === "errored") {+            action(stream[storedError_]);+        }+        else {+            promise.catch(action);+        }+    }+    function onStreamClosed(stream, promise, action) {+        if (stream[state_] === "closed") {+            action();+        }+        else {+            promise.then(action);+        }+    }+    onStreamErrored(source, reader[closedPromise_].promise, error => {+        if (!preventAbort) {+            shutDown(() => writableStreamAbort(dest, error), { actualError: error });+        }+        else {+            shutDown(undefined, { actualError: error });+        }+    });+    onStreamErrored(dest, writer[closedPromise_$1].promise, error => {+        if (!preventCancel) {+            shutDown(() => readableStreamCancel(source, error), { actualError: error });+        }+        else {+            shutDown(undefined, { actualError: error });+        }+    });+    onStreamClosed(source, reader[closedPromise_].promise, () => {+        if (!preventClose) {+            shutDown(() => writableStreamDefaultWriterCloseWithErrorPropagation(writer));+        }+        else {+            shutDown();+        }+    });+    if (writableStreamCloseQueuedOrInFlight(dest) || dest[state_] === "closed") {+        const destClosed = new TypeError();+        if (!preventCancel) {+            shutDown(() => readableStreamCancel(source, destClosed), { actualError: destClosed });+        }+        else {+            shutDown(undefined, { actualError: destClosed });+        }+    }+    function awaitLatestWrite() {+        const curLatestWrite = latestWrite;+        return latestWrite.then(() => curLatestWrite === latestWrite ? undefined : awaitLatestWrite());+    }+    function flushRemainder() {+        if (dest[state_] === "writable" && (!writableStreamCloseQueuedOrInFlight(dest))) {+            return awaitLatestWrite();+        }+        else {+            return undefined;+        }+    }+    function shutDown(action, error) {+        if (shuttingDown) {+            return;+        }+        shuttingDown = true;+        if (action === undefined) {+            action = () => Promise.resolve();+        }+        function finishShutDown() {+            action().then(_ => finalize(error), newError => finalize({ actualError: newError }));+        }+        const flushWait = flushRemainder();+        if (flushWait) {+            flushWait.then(finishShutDown);+        }+        else {+            finishShutDown();+        }+    }+    function finalize(error) {+        writableStreamDefaultWriterRelease(writer);+        readableStreamReaderGenericRelease(reader);+        if (signal && abortAlgorithm) {+            signal.removeEventListener("abort", abortAlgorithm);+        }+        if (error) {+            promise.reject(error.actualError);+        }+        else {+            promise.resolve(undefined);+        }+    }+    function next() {+        if (shuttingDown) {+            return;+        }+        writer[readyPromise_].promise.then(() => {+            readableStreamDefaultReaderRead(reader).then(({ value, done }) => {+                if (done) {+                    return;+                }+                latestWrite = writableStreamDefaultWriterWrite(writer, value).catch(() => { });+                next();+            }, _error => {+                latestWrite = Promise.resolve();+            });+        });+    }+    if (!shuttingDown) {+        next();+    }+    return promise.promise;+}++class ReadableStreamDefaultController {+    constructor() {+        throw new TypeError();+    }+    get desiredSize() {+        ret

@ry it is! It's actually really nice TypeScript with an MIT license, so we could pull the source in directly: https://github.com/stardazed/sd-streams/tree/master/packages/streams/src

mrkurt

comment created time in 20 days

Pull request review commentdenoland/deno

Global request / response

+/**+* @stardazed/streams - implementation of the web streams standard+* Part of Stardazed+* (c) 2018-Present by Arthur Langereis - @zenmumbler+* https://github.com/stardazed/sd-streams+*/++const state_ = Symbol("state_");+const storedError_ = Symbol("storedError_");+function isInteger(value) {+    if (!isFinite(value)) {+        return false;+    }+    const absValue = Math.abs(value);+    return Math.floor(absValue) === absValue;+}+function isFiniteNonNegativeNumber(value) {+    if (!(typeof value === "number" && isFinite(value))) {+        return false;+    }+    return value >= 0;+}+function isAbortSignal(signal) {+    if (typeof signal !== "object" || signal === null) {+        return false;+    }+    try {+        const aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, "aborted").get;+        aborted.call(signal);+        return true;+    }+    catch (err) {+        return false;+    }+}+function invokeOrNoop(o, p, args) {+    const method = o[p];+    if (method === undefined) {+        return undefined;+    }+    return Function.prototype.apply.call(method, o, args);+}+function cloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, cloneConstructor) {+    return srcBuffer.slice(srcByteOffset, srcByteOffset + srcLength);+}+function transferArrayBuffer(buffer) {+    return buffer.slice(0);+}+function copyDataBlockBytes(toBlock, toIndex, fromBlock, fromIndex, count) {+    new Uint8Array(toBlock, toIndex, count).set(new Uint8Array(fromBlock, fromIndex, count));+}+const objectCloneMemo = new WeakMap();+let sharedArrayBufferSupported_;+function supportsSharedArrayBuffer() {+    if (sharedArrayBufferSupported_ === undefined) {+        try {+            new SharedArrayBuffer(16);+            sharedArrayBufferSupported_ = true;+        }+        catch (e) {+            sharedArrayBufferSupported_ = false;+        }+    }+    return sharedArrayBufferSupported_;+}+function cloneValue(value) {+    const valueType = typeof value;+    switch (valueType) {+        case "number":+        case "string":+        case "boolean":+        case "undefined":+        case "bigint":+            return value;+        case "object": {+            if (objectCloneMemo.has(value)) {+                return objectCloneMemo.get(value);+            }+            if (value === null) {+                return value;+            }+            if (value instanceof Date) {+                return new Date(value.valueOf());+            }+            if (value instanceof RegExp) {+                return new RegExp(value);+            }+            if (supportsSharedArrayBuffer() && value instanceof SharedArrayBuffer) {+                return value;+            }+            if (value instanceof ArrayBuffer) {+                const cloned = cloneArrayBuffer(value, 0, value.byteLength, ArrayBuffer);+                objectCloneMemo.set(value, cloned);+                return cloned;+            }+            if (ArrayBuffer.isView(value)) {+                const clonedBuffer = cloneValue(value.buffer);+                let length;+                if (value instanceof DataView) {+                    length = value.byteLength;+                }+                else {+                    length = value.length;+                }+                return new value.constructor(clonedBuffer, value.byteOffset, length);+            }+            if (value instanceof Map) {+                const clonedMap = new Map();+                objectCloneMemo.set(value, clonedMap);+                value.forEach((v, k) => clonedMap.set(k, cloneValue(v)));+                return clonedMap;+            }+            if (value instanceof Set) {+                const clonedSet = new Map();+                objectCloneMemo.set(value, clonedSet);+                value.forEach((v, k) => clonedSet.set(k, cloneValue(v)));+                return clonedSet;+            }+            const clonedObj = {};+            objectCloneMemo.set(value, clonedObj);+            const sourceKeys = Object.getOwnPropertyNames(value);+            for (const key of sourceKeys) {+                clonedObj[key] = cloneValue(value[key]);+            }+            return clonedObj;+        }+        case "symbol":+        case "function":+        default:+            throw new DOMException("Uncloneable value in stream", "DataCloneError");+    }+}+function promiseCall(f, v, args) {+    try {+        const result = Function.prototype.apply.call(f, v, args);+        return Promise.resolve(result);+    }+    catch (err) {+        return Promise.reject(err);+    }+}+function createAlgorithmFromUnderlyingMethod(obj, methodName, extraArgs) {+    const method = obj[methodName];+    if (method === undefined) {+        return () => Promise.resolve(undefined);+    }+    if (typeof method !== "function") {+        throw new TypeError(`Field "${methodName}" is not a function.`);+    }+    return function (...fnArgs) {+        return promiseCall(method, obj, fnArgs.concat(extraArgs));+    };+}+function validateAndNormalizeHighWaterMark(hwm) {+    const highWaterMark = Number(hwm);+    if (isNaN(highWaterMark) || highWaterMark < 0) {+        throw new RangeError("highWaterMark must be a valid, non-negative integer.");+    }+    return highWaterMark;+}+function makeSizeAlgorithmFromSizeFunction(sizeFn) {+    if (typeof sizeFn !== "function" && typeof sizeFn !== "undefined") {+        throw new TypeError("size function must be undefined or a function");+    }+    return function (chunk) {+        if (typeof sizeFn === "function") {+            return sizeFn(chunk);+        }+        return 1;+    };+}+var ControlledPromiseState;+(function (ControlledPromiseState) {+    ControlledPromiseState[ControlledPromiseState["Pending"] = 0] = "Pending";+    ControlledPromiseState[ControlledPromiseState["Resolved"] = 1] = "Resolved";+    ControlledPromiseState[ControlledPromiseState["Rejected"] = 2] = "Rejected";+})(ControlledPromiseState || (ControlledPromiseState = {}));+function createControlledPromise() {+    const conProm = {+        state: ControlledPromiseState.Pending+    };+    conProm.promise = new Promise(function (resolve, reject) {+        conProm.resolve = function (v) { conProm.state = ControlledPromiseState.Resolved; resolve(v); };+        conProm.reject = function (e) { conProm.state = ControlledPromiseState.Rejected; reject(e); };+    });+    return conProm;+}++const CHUNK_SIZE = 16384;+class QueueImpl {+    constructor() {+        this.chunks_ = [[]];+        this.readChunk_ = this.writeChunk_ = this.chunks_[0];+        this.length_ = 0;+    }+    push(t) {+        this.writeChunk_.push(t);+        this.length_ += 1;+        if (this.writeChunk_.length === CHUNK_SIZE) {+            this.writeChunk_ = [];+            this.chunks_.push(this.writeChunk_);+        }+    }+    front() {+        if (this.length_ === 0) {+            return undefined;+        }+        return this.readChunk_[0];+    }+    shift() {+        if (this.length_ === 0) {+            return undefined;+        }+        const t = this.readChunk_.shift();+        this.length_ -= 1;+        if (this.readChunk_.length === 0 && this.readChunk_ !== this.writeChunk_) {+            this.chunks_.shift();+            this.readChunk_ = this.chunks_[0];+        }+        return t;+    }+    get length() {+        return this.length_;+    }+}++const queue_ = Symbol("queue_");+const queueTotalSize_ = Symbol("queueTotalSize_");+function dequeueValue(container) {+    const pair = container[queue_].shift();+    const newTotalSize = container[queueTotalSize_] - pair.size;+    container[queueTotalSize_] = Math.max(0, newTotalSize);+    return pair.value;+}+function enqueueValueWithSize(container, value, size) {+    if (!isFiniteNonNegativeNumber(size)) {+        throw new RangeError("Chunk size must be a non-negative, finite numbers");+    }+    container[queue_].push({ value, size });+    container[queueTotalSize_] += size;+}+function peekQueueValue(container) {+    return container[queue_].front().value;+}+function resetQueue(container) {+    container[queue_] = new QueueImpl();+    container[queueTotalSize_] = 0;+}++const controlledReadableStream_ = Symbol("controlledReadableStream_");+const pullAlgorithm_ = Symbol("pullAlgorithm_");+const cancelAlgorithm_ = Symbol("cancelAlgorithm_");+const strategySizeAlgorithm_ = Symbol("strategySizeAlgorithm_");+const strategyHWM_ = Symbol("strategyHWM_");+const started_ = Symbol("started_");+const closeRequested_ = Symbol("closeRequested_");+const pullAgain_ = Symbol("pullAgain_");+const pulling_ = Symbol("pulling_");+const cancelSteps_ = Symbol("cancelSteps_");+const pullSteps_ = Symbol("pullSteps_");+const autoAllocateChunkSize_ = Symbol("autoAllocateChunkSize_");+const byobRequest_ = Symbol("byobRequest_");+const controlledReadableByteStream_ = Symbol("controlledReadableByteStream_");+const pendingPullIntos_ = Symbol("pendingPullIntos_");+const closedPromise_ = Symbol("closedPromise_");+const ownerReadableStream_ = Symbol("ownerReadableStream_");+const readRequests_ = Symbol("readRequests_");+const readIntoRequests_ = Symbol("readIntoRequests_");+const associatedReadableByteStreamController_ = Symbol("associatedReadableByteStreamController_");+const view_ = Symbol("view_");+const reader_ = Symbol("reader_");+const readableStreamController_ = Symbol("readableStreamController_");+function initializeReadableStream(stream) {+    stream[state_] = "readable";+    stream[reader_] = undefined;+    stream[storedError_] = undefined;+    stream[readableStreamController_] = undefined;+}+function isReadableStream(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return readableStreamController_ in value;+}+function isReadableStreamLocked(stream) {+    return stream[reader_] !== undefined;+}+function readableStreamGetNumReadIntoRequests(stream) {+    const reader = stream[reader_];+    if (reader === undefined) {+        return 0;+    }+    return reader[readIntoRequests_].length;+}+function readableStreamGetNumReadRequests(stream) {+    const reader = stream[reader_];+    if (reader === undefined) {+        return 0;+    }+    return reader[readRequests_].length;+}+function readableStreamCreateReadResult(value, done, forAuthorCode) {+    const prototype = forAuthorCode ? Object.prototype : null;+    const result = Object.create(prototype);+    result.value = value;+    result.done = done;+    return result;+}+function readableStreamAddReadIntoRequest(stream, forAuthorCode) {+    const reader = stream[reader_];+    const conProm = createControlledPromise();+    conProm.forAuthorCode = forAuthorCode;+    reader[readIntoRequests_].push(conProm);+    return conProm.promise;+}+function readableStreamAddReadRequest(stream, forAuthorCode) {+    const reader = stream[reader_];+    const conProm = createControlledPromise();+    conProm.forAuthorCode = forAuthorCode;+    reader[readRequests_].push(conProm);+    return conProm.promise;+}+function readableStreamHasBYOBReader(stream) {+    const reader = stream[reader_];+    return isReadableStreamBYOBReader(reader);+}+function readableStreamHasDefaultReader(stream) {+    const reader = stream[reader_];+    return isReadableStreamDefaultReader(reader);+}+function readableStreamCancel(stream, reason) {+    if (stream[state_] === "closed") {+        return Promise.resolve(undefined);+    }+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    readableStreamClose(stream);+    const sourceCancelPromise = stream[readableStreamController_][cancelSteps_](reason);+    return sourceCancelPromise.then(_ => undefined);+}+function readableStreamClose(stream) {+    stream[state_] = "closed";+    const reader = stream[reader_];+    if (reader === undefined) {+        return;+    }+    if (isReadableStreamDefaultReader(reader)) {+        for (const readRequest of reader[readRequests_]) {+            readRequest.resolve(readableStreamCreateReadResult(undefined, true, readRequest.forAuthorCode));+        }+        reader[readRequests_] = [];+    }+    reader[closedPromise_].resolve();+    reader[closedPromise_].promise.catch(() => { });+}+function readableStreamError(stream, error) {+    if (stream[state_] !== "readable") {+        throw new RangeError("Stream is in an invalid state");+    }+    stream[state_] = "errored";+    stream[storedError_] = error;+    const reader = stream[reader_];+    if (reader === undefined) {+        return;+    }+    if (isReadableStreamDefaultReader(reader)) {+        for (const readRequest of reader[readRequests_]) {+            readRequest.reject(error);+        }+        reader[readRequests_] = [];+    }+    else {+        const readIntoRequests = reader[readIntoRequests_];+        for (const readIntoRequest of readIntoRequests) {+            readIntoRequest.reject(error);+        }+        reader[readIntoRequests_] = [];+    }+    reader[closedPromise_].reject(error);+}+function isReadableStreamDefaultReader(reader) {+    if (typeof reader !== "object" || reader === null) {+        return false;+    }+    return readRequests_ in reader;+}+function isReadableStreamBYOBReader(reader) {+    if (typeof reader !== "object" || reader === null) {+        return false;+    }+    return readIntoRequests_ in reader;+}+function readableStreamReaderGenericInitialize(reader, stream) {+    reader[ownerReadableStream_] = stream;+    stream[reader_] = reader;+    const streamState = stream[state_];+    reader[closedPromise_] = createControlledPromise();+    if (streamState === "readable") ;+    else if (streamState === "closed") {+        reader[closedPromise_].resolve(undefined);+    }+    else {+        reader[closedPromise_].reject(stream[storedError_]);+        reader[closedPromise_].promise.catch(() => { });+    }+}+function readableStreamReaderGenericRelease(reader) {+    const stream = reader[ownerReadableStream_];+    if (stream === undefined) {+        throw new TypeError("Reader is in an inconsistent state");+    }+    if (stream[state_] === "readable") ;+    else {+        reader[closedPromise_] = createControlledPromise();+    }+    reader[closedPromise_].reject(new TypeError());+    reader[closedPromise_].promise.catch(() => { });+    stream[reader_] = undefined;+    reader[ownerReadableStream_] = undefined;+}+function readableStreamBYOBReaderRead(reader, view, forAuthorCode = false) {+    const stream = reader[ownerReadableStream_];+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return readableByteStreamControllerPullInto(stream[readableStreamController_], view, forAuthorCode);+}+function readableStreamDefaultReaderRead(reader, forAuthorCode = false) {+    const stream = reader[ownerReadableStream_];+    if (stream[state_] === "closed") {+        return Promise.resolve(readableStreamCreateReadResult(undefined, true, forAuthorCode));+    }+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return stream[readableStreamController_][pullSteps_](forAuthorCode);+}+function readableStreamFulfillReadIntoRequest(stream, chunk, done) {+    const reader = stream[reader_];+    const readIntoRequest = reader[readIntoRequests_].shift();+    readIntoRequest.resolve(readableStreamCreateReadResult(chunk, done, readIntoRequest.forAuthorCode));+}+function readableStreamFulfillReadRequest(stream, chunk, done) {+    const reader = stream[reader_];+    const readRequest = reader[readRequests_].shift();+    readRequest.resolve(readableStreamCreateReadResult(chunk, done, readRequest.forAuthorCode));+}+function setUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {+    controller[controlledReadableStream_] = stream;+    resetQueue(controller);+    controller[started_] = false;+    controller[closeRequested_] = false;+    controller[pullAgain_] = false;+    controller[pulling_] = false;+    controller[strategySizeAlgorithm_] = sizeAlgorithm;+    controller[strategyHWM_] = highWaterMark;+    controller[pullAlgorithm_] = pullAlgorithm;+    controller[cancelAlgorithm_] = cancelAlgorithm;+    stream[readableStreamController_] = controller;+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_] = true;+        readableStreamDefaultControllerCallPullIfNeeded(controller);+    }, error => {+        readableStreamDefaultControllerError(controller, error);+    });+}+function isReadableStreamDefaultController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledReadableStream_ in value;+}+function readableStreamDefaultControllerHasBackpressure(controller) {+    return !readableStreamDefaultControllerShouldCallPull(controller);+}+function readableStreamDefaultControllerCanCloseOrEnqueue(controller) {+    const state = controller[controlledReadableStream_][state_];+    return controller[closeRequested_] === false && state === "readable";+}+function readableStreamDefaultControllerGetDesiredSize(controller) {+    const state = controller[controlledReadableStream_][state_];+    if (state === "errored") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return controller[strategyHWM_] - controller[queueTotalSize_];+}+function readableStreamDefaultControllerClose(controller) {+    controller[closeRequested_] = true;+    const stream = controller[controlledReadableStream_];+    if (controller[queue_].length === 0) {+        readableStreamDefaultControllerClearAlgorithms(controller);+        readableStreamClose(stream);+    }+}+function readableStreamDefaultControllerEnqueue(controller, chunk) {+    const stream = controller[controlledReadableStream_];+    if (isReadableStreamLocked(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        readableStreamFulfillReadRequest(stream, chunk, false);+    }+    else {+        let chunkSize;+        try {+            chunkSize = controller[strategySizeAlgorithm_](chunk);+        }+        catch (error) {+            readableStreamDefaultControllerError(controller, error);+            throw error;+        }+        try {+            enqueueValueWithSize(controller, chunk, chunkSize);+        }+        catch (error) {+            readableStreamDefaultControllerError(controller, error);+            throw error;+        }+    }+    readableStreamDefaultControllerCallPullIfNeeded(controller);+}+function readableStreamDefaultControllerError(controller, error) {+    const stream = controller[controlledReadableStream_];+    if (stream[state_] !== "readable") {+        return;+    }+    resetQueue(controller);+    readableStreamDefaultControllerClearAlgorithms(controller);+    readableStreamError(stream, error);+}+function readableStreamDefaultControllerCallPullIfNeeded(controller) {+    if (!readableStreamDefaultControllerShouldCallPull(controller)) {+        return;+    }+    if (controller[pulling_]) {+        controller[pullAgain_] = true;+        return;+    }+    if (controller[pullAgain_]) {+        throw new RangeError("Stream controller is in an invalid state.");+    }+    controller[pulling_] = true;+    controller[pullAlgorithm_](controller).then(_ => {+        controller[pulling_] = false;+        if (controller[pullAgain_]) {+            controller[pullAgain_] = false;+            readableStreamDefaultControllerCallPullIfNeeded(controller);+        }+    }, error => {+        readableStreamDefaultControllerError(controller, error);+    });+}+function readableStreamDefaultControllerShouldCallPull(controller) {+    const stream = controller[controlledReadableStream_];+    if (!readableStreamDefaultControllerCanCloseOrEnqueue(controller)) {+        return false;+    }+    if (controller[started_] === false) {+        return false;+    }+    if (isReadableStreamLocked(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        return true;+    }+    const desiredSize = readableStreamDefaultControllerGetDesiredSize(controller);+    if (desiredSize === null) {+        throw new RangeError("Stream is in an invalid state.");+    }+    return desiredSize > 0;+}+function readableStreamDefaultControllerClearAlgorithms(controller) {+    controller[pullAlgorithm_] = undefined;+    controller[cancelAlgorithm_] = undefined;+    controller[strategySizeAlgorithm_] = undefined;+}+function setUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {+    if (stream[readableStreamController_] !== undefined) {+        throw new TypeError("Cannot reuse streams");+    }+    if (autoAllocateChunkSize !== undefined) {+        if (!isInteger(autoAllocateChunkSize) || autoAllocateChunkSize <= 0) {+            throw new RangeError("autoAllocateChunkSize must be a positive, finite integer");+        }+    }+    controller[controlledReadableByteStream_] = stream;+    controller[pullAgain_] = false;+    controller[pulling_] = false;+    readableByteStreamControllerClearPendingPullIntos(controller);+    resetQueue(controller);+    controller[closeRequested_] = false;+    controller[started_] = false;+    controller[strategyHWM_] = validateAndNormalizeHighWaterMark(highWaterMark);+    controller[pullAlgorithm_] = pullAlgorithm;+    controller[cancelAlgorithm_] = cancelAlgorithm;+    controller[autoAllocateChunkSize_] = autoAllocateChunkSize;+    controller[pendingPullIntos_] = [];+    stream[readableStreamController_] = controller;+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_] = true;+        readableByteStreamControllerCallPullIfNeeded(controller);+    }, error => {+        readableByteStreamControllerError(controller, error);+    });+}+function isReadableStreamBYOBRequest(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return associatedReadableByteStreamController_ in value;+}+function isReadableByteStreamController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledReadableByteStream_ in value;+}+function readableByteStreamControllerCallPullIfNeeded(controller) {+    if (!readableByteStreamControllerShouldCallPull(controller)) {+        return;+    }+    if (controller[pulling_]) {+        controller[pullAgain_] = true;+        return;+    }+    controller[pulling_] = true;+    controller[pullAlgorithm_](controller).then(_ => {+        controller[pulling_] = false;+        if (controller[pullAgain_]) {+            controller[pullAgain_] = false;+            readableByteStreamControllerCallPullIfNeeded(controller);+        }+    }, error => {+        readableByteStreamControllerError(controller, error);+    });+}+function readableByteStreamControllerClearAlgorithms(controller) {+    controller[pullAlgorithm_] = undefined;+    controller[cancelAlgorithm_] = undefined;+}+function readableByteStreamControllerClearPendingPullIntos(controller) {+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    controller[pendingPullIntos_] = [];+}+function readableByteStreamControllerClose(controller) {+    const stream = controller[controlledReadableByteStream_];+    if (controller[queueTotalSize_] > 0) {+        controller[closeRequested_] = true;+        return;+    }+    if (controller[pendingPullIntos_].length > 0) {+        const firstPendingPullInto = controller[pendingPullIntos_][0];+        if (firstPendingPullInto.bytesFilled > 0) {+            const error = new TypeError();+            readableByteStreamControllerError(controller, error);+            throw error;+        }+    }+    readableByteStreamControllerClearAlgorithms(controller);+    readableStreamClose(stream);+}+function readableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {+    let done = false;+    if (stream[state_] === "closed") {+        done = true;+    }+    const filledView = readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);+    if (pullIntoDescriptor.readerType === "default") {+        readableStreamFulfillReadRequest(stream, filledView, done);+    }+    else {+        readableStreamFulfillReadIntoRequest(stream, filledView, done);+    }+}+function readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {+    const { bytesFilled, elementSize } = pullIntoDescriptor;+    return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);+}+function readableByteStreamControllerEnqueue(controller, chunk) {+    const stream = controller[controlledReadableByteStream_];+    const { buffer, byteOffset, byteLength } = chunk;+    const transferredBuffer = transferArrayBuffer(buffer);+    if (readableStreamHasDefaultReader(stream)) {+        if (readableStreamGetNumReadRequests(stream) === 0) {+            readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+        }+        else {+            const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);+            readableStreamFulfillReadRequest(stream, transferredView, false);+        }+    }+    else if (readableStreamHasBYOBReader(stream)) {+        readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+        readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);+    }+    else {+        readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+    }+    readableByteStreamControllerCallPullIfNeeded(controller);+}+function readableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {+    controller[queue_].push({ buffer, byteOffset, byteLength });+    controller[queueTotalSize_] += byteLength;+}+function readableByteStreamControllerError(controller, error) {+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] !== "readable") {+        return;+    }+    readableByteStreamControllerClearPendingPullIntos(controller);+    resetQueue(controller);+    readableByteStreamControllerClearAlgorithms(controller);+    readableStreamError(stream, error);+}+function readableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    pullIntoDescriptor.bytesFilled += size;+}+function readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {+    const elementSize = pullIntoDescriptor.elementSize;+    const currentAlignedBytes = pullIntoDescriptor.bytesFilled - (pullIntoDescriptor.bytesFilled % elementSize);+    const maxBytesToCopy = Math.min(controller[queueTotalSize_], pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);+    const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;+    const maxAlignedBytes = maxBytesFilled - (maxBytesFilled % elementSize);+    let totalBytesToCopyRemaining = maxBytesToCopy;+    let ready = false;+    if (maxAlignedBytes > currentAlignedBytes) {+        totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;+        ready = true;+    }+    const queue = controller[queue_];+    while (totalBytesToCopyRemaining > 0) {+        const headOfQueue = queue.front();+        const bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);+        const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;+        copyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);+        if (headOfQueue.byteLength === bytesToCopy) {+            queue.shift();+        }+        else {+            headOfQueue.byteOffset += bytesToCopy;+            headOfQueue.byteLength -= bytesToCopy;+        }+        controller[queueTotalSize_] -= bytesToCopy;+        readableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);+        totalBytesToCopyRemaining -= bytesToCopy;+    }+    return ready;+}+function readableByteStreamControllerGetDesiredSize(controller) {+    const stream = controller[controlledReadableByteStream_];+    const state = stream[state_];+    if (state === "errored") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return controller[strategyHWM_] - controller[queueTotalSize_];+}+function readableByteStreamControllerHandleQueueDrain(controller) {+    if (controller[queueTotalSize_] === 0 && controller[closeRequested_]) {+        readableByteStreamControllerClearAlgorithms(controller);+        readableStreamClose(controller[controlledReadableByteStream_]);+    }+    else {+        readableByteStreamControllerCallPullIfNeeded(controller);+    }+}+function readableByteStreamControllerInvalidateBYOBRequest(controller) {+    const byobRequest = controller[byobRequest_];+    if (byobRequest === undefined) {+        return;+    }+    byobRequest[associatedReadableByteStreamController_] = undefined;+    byobRequest[view_] = undefined;+    controller[byobRequest_] = undefined;+}+function readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {+    const pendingPullIntos = controller[pendingPullIntos_];+    while (pendingPullIntos.length > 0) {+        if (controller[queueTotalSize_] === 0) {+            return;+        }+        const pullIntoDescriptor = pendingPullIntos[0];+        if (readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {+            readableByteStreamControllerShiftPendingPullInto(controller);+            readableByteStreamControllerCommitPullIntoDescriptor(controller[controlledReadableByteStream_], pullIntoDescriptor);+        }+    }+}+function readableByteStreamControllerPullInto(controller, view, forAuthorCode) {+    const stream = controller[controlledReadableByteStream_];+    const elementSize = view.BYTES_PER_ELEMENT || 1;+    const ctor = view.constructor;+    const byteOffset = view.byteOffset;+    const byteLength = view.byteLength;+    const buffer = transferArrayBuffer(view.buffer);+    const pullIntoDescriptor = { buffer, byteOffset, byteLength, bytesFilled: 0, elementSize, ctor, readerType: "byob" };+    if (controller[pendingPullIntos_].length > 0) {+        controller[pendingPullIntos_].push(pullIntoDescriptor);+        return readableStreamAddReadIntoRequest(stream, forAuthorCode);+    }+    if (stream[state_] === "closed") {+        const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);+        return Promise.resolve(readableStreamCreateReadResult(emptyView, true, forAuthorCode));+    }+    if (controller[queueTotalSize_] > 0) {+        if (readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {+            const filledView = readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);+            readableByteStreamControllerHandleQueueDrain(controller);+            return Promise.resolve(readableStreamCreateReadResult(filledView, false, forAuthorCode));+        }+        if (controller[closeRequested_]) {+            const error = new TypeError();+            readableByteStreamControllerError(controller, error);+            return Promise.reject(error);+        }+    }+    controller[pendingPullIntos_].push(pullIntoDescriptor);+    const promise = readableStreamAddReadIntoRequest(stream, forAuthorCode);+    readableByteStreamControllerCallPullIfNeeded(controller);+    return promise;+}+function readableByteStreamControllerRespond(controller, bytesWritten) {+    bytesWritten = Number(bytesWritten);+    if (!isFiniteNonNegativeNumber(bytesWritten)) {+        throw new RangeError("bytesWritten must be a finite, non-negative number");+    }+    readableByteStreamControllerRespondInternal(controller, bytesWritten);+}+function readableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {+    firstDescriptor.buffer = transferArrayBuffer(firstDescriptor.buffer);+    const stream = controller[controlledReadableByteStream_];+    if (readableStreamHasBYOBReader(stream)) {+        while (readableStreamGetNumReadIntoRequests(stream) > 0) {+            const pullIntoDescriptor = readableByteStreamControllerShiftPendingPullInto(controller);+            readableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);+        }+    }+}+function readableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {+    if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {+        throw new RangeError();+    }+    readableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);+    if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {+        return;+    }+    readableByteStreamControllerShiftPendingPullInto(controller);+    const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;+    if (remainderSize > 0) {+        const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;+        const remainder = cloneArrayBuffer(pullIntoDescriptor.buffer, end - remainderSize, remainderSize, ArrayBuffer);+        readableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);+    }+    pullIntoDescriptor.buffer = transferArrayBuffer(pullIntoDescriptor.buffer);+    pullIntoDescriptor.bytesFilled = pullIntoDescriptor.bytesFilled - remainderSize;+    readableByteStreamControllerCommitPullIntoDescriptor(controller[controlledReadableByteStream_], pullIntoDescriptor);+    readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);+}+function readableByteStreamControllerRespondInternal(controller, bytesWritten) {+    const firstDescriptor = controller[pendingPullIntos_][0];+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] === "closed") {+        if (bytesWritten !== 0) {+            throw new TypeError();+        }+        readableByteStreamControllerRespondInClosedState(controller, firstDescriptor);+    }+    else {+        readableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);+    }+    readableByteStreamControllerCallPullIfNeeded(controller);+}+function readableByteStreamControllerRespondWithNewView(controller, view) {+    const firstDescriptor = controller[pendingPullIntos_][0];+    if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {+        throw new RangeError();+    }+    if (firstDescriptor.byteLength !== view.byteLength) {+        throw new RangeError();+    }+    firstDescriptor.buffer = view.buffer;+    readableByteStreamControllerRespondInternal(controller, view.byteLength);+}+function readableByteStreamControllerShiftPendingPullInto(controller) {+    const descriptor = controller[pendingPullIntos_].shift();+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    return descriptor;+}+function readableByteStreamControllerShouldCallPull(controller) {+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] !== "readable") {+        return false;+    }+    if (controller[closeRequested_]) {+        return false;+    }+    if (!controller[started_]) {+        return false;+    }+    if (readableStreamHasDefaultReader(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        return true;+    }+    if (readableStreamHasBYOBReader(stream) && readableStreamGetNumReadIntoRequests(stream) > 0) {+        return true;+    }+    const desiredSize = readableByteStreamControllerGetDesiredSize(controller);+    return desiredSize > 0;+}+function setUpReadableStreamBYOBRequest(request, controller, view) {+    if (!isReadableByteStreamController(controller)) {+        throw new TypeError();+    }+    if (!ArrayBuffer.isView(view)) {+        throw new TypeError();+    }+    request[associatedReadableByteStreamController_] = controller;+    request[view_] = view;+}++const backpressure_ = Symbol("backpressure_");+const closeRequest_ = Symbol("closeRequest_");+const inFlightWriteRequest_ = Symbol("inFlightWriteRequest_");+const inFlightCloseRequest_ = Symbol("inFlightCloseRequest_");+const pendingAbortRequest_ = Symbol("pendingAbortRequest_");+const writableStreamController_ = Symbol("writableStreamController_");+const writer_ = Symbol("writer_");+const writeRequests_ = Symbol("writeRequests_");+const abortAlgorithm_ = Symbol("abortAlgorithm_");+const closeAlgorithm_ = Symbol("closeAlgorithm_");+const controlledWritableStream_ = Symbol("controlledWritableStream_");+const started_$1 = Symbol("started_");+const strategyHWM_$1 = Symbol("strategyHWM_");+const strategySizeAlgorithm_$1 = Symbol("strategySizeAlgorithm_");+const writeAlgorithm_ = Symbol("writeAlgorithm_");+const ownerWritableStream_ = Symbol("ownerWritableStream_");+const closedPromise_$1 = Symbol("closedPromise_");+const readyPromise_ = Symbol("readyPromise_");+const errorSteps_ = Symbol("errorSteps_");+const abortSteps_ = Symbol("abortSteps_");+function initializeWritableStream(stream) {+    stream[state_] = "writable";+    stream[storedError_] = undefined;+    stream[writer_] = undefined;+    stream[writableStreamController_] = undefined;+    stream[inFlightWriteRequest_] = undefined;+    stream[closeRequest_] = undefined;+    stream[inFlightCloseRequest_] = undefined;+    stream[pendingAbortRequest_] = undefined;+    stream[writeRequests_] = [];+    stream[backpressure_] = false;+}+function isWritableStream(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return writableStreamController_ in value;+}+function isWritableStreamLocked(stream) {+    return stream[writer_] !== undefined;+}+function writableStreamAbort(stream, reason) {+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return Promise.resolve(undefined);+    }+    let pending = stream[pendingAbortRequest_];+    if (pending !== undefined) {+        return pending.promise;+    }+    let wasAlreadyErroring = false;+    if (state === "erroring") {+        wasAlreadyErroring = true;+        reason = undefined;+    }+    pending = {+        reason,+        wasAlreadyErroring+    };+    const promise = new Promise((resolve, reject) => {+        pending.resolve = resolve;+        pending.reject = reject;+    });+    pending.promise = promise;+    stream[pendingAbortRequest_] = pending;+    if (!wasAlreadyErroring) {+        writableStreamStartErroring(stream, reason);+    }+    return promise;+}+function writableStreamAddWriteRequest(stream) {+    const writePromise = createControlledPromise();+    stream[writeRequests_].push(writePromise);+    return writePromise.promise;+}+function writableStreamDealWithRejection(stream, error) {+    const state = stream[state_];+    if (state === "writable") {+        writableStreamStartErroring(stream, error);+        return;+    }+    writableStreamFinishErroring(stream);+}+function writableStreamStartErroring(stream, reason) {+    const controller = stream[writableStreamController_];+    stream[state_] = "erroring";+    stream[storedError_] = reason;+    const writer = stream[writer_];+    if (writer !== undefined) {+        writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);+    }+    if (!writableStreamHasOperationMarkedInFlight(stream) && controller[started_$1]) {+        writableStreamFinishErroring(stream);+    }+}+function writableStreamFinishErroring(stream) {+    stream[state_] = "errored";+    const controller = stream[writableStreamController_];+    controller[errorSteps_]();+    const storedError = stream[storedError_];+    for (const writeRequest of stream[writeRequests_]) {+        writeRequest.reject(storedError);+    }+    stream[writeRequests_] = [];+    const abortRequest = stream[pendingAbortRequest_];+    if (abortRequest === undefined) {+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+        return;+    }+    stream[pendingAbortRequest_] = undefined;+    if (abortRequest.wasAlreadyErroring) {+        abortRequest.reject(storedError);+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+        return;+    }+    const promise = controller[abortSteps_](abortRequest.reason);+    promise.then(_ => {+        abortRequest.resolve();+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+    }, error => {+        abortRequest.reject(error);+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+    });+}+function writableStreamFinishInFlightWrite(stream) {+    stream[inFlightWriteRequest_].resolve(undefined);+    stream[inFlightWriteRequest_] = undefined;+}+function writableStreamFinishInFlightWriteWithError(stream, error) {+    stream[inFlightWriteRequest_].reject(error);+    stream[inFlightWriteRequest_] = undefined;+    writableStreamDealWithRejection(stream, error);+}+function writableStreamFinishInFlightClose(stream) {+    stream[inFlightCloseRequest_].resolve(undefined);+    stream[inFlightCloseRequest_] = undefined;+    const state = stream[state_];+    if (state === "erroring") {+        stream[storedError_] = undefined;+        if (stream[pendingAbortRequest_] !== undefined) {+            stream[pendingAbortRequest_].resolve();+            stream[pendingAbortRequest_] = undefined;+        }+    }+    stream[state_] = "closed";+    const writer = stream[writer_];+    if (writer !== undefined) {+        writer[closedPromise_$1].resolve(undefined);+    }+}+function writableStreamFinishInFlightCloseWithError(stream, error) {+    stream[inFlightCloseRequest_].reject(error);+    stream[inFlightCloseRequest_] = undefined;+    if (stream[pendingAbortRequest_] !== undefined) {+        stream[pendingAbortRequest_].reject(error);+        stream[pendingAbortRequest_] = undefined;+    }+    writableStreamDealWithRejection(stream, error);+}+function writableStreamCloseQueuedOrInFlight(stream) {+    return (stream[closeRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined);+}+function writableStreamHasOperationMarkedInFlight(stream) {+    return stream[inFlightWriteRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined;+}+function writableStreamMarkCloseRequestInFlight(stream) {+    stream[inFlightCloseRequest_] = stream[closeRequest_];+    stream[closeRequest_] = undefined;+}+function writableStreamMarkFirstWriteRequestInFlight(stream) {+    const writeRequest = stream[writeRequests_].shift();+    stream[inFlightWriteRequest_] = writeRequest;+}+function writableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {+    const closeRequest = stream[closeRequest_];+    if (closeRequest !== undefined) {+        closeRequest.reject(stream[storedError_]);+        stream[closeRequest_] = undefined;+    }+    const writer = stream[writer_];+    if (writer !== undefined) {+        writer[closedPromise_$1].reject(stream[storedError_]);+        writer[closedPromise_$1].promise.catch(() => { });+    }+}+function writableStreamUpdateBackpressure(stream, backpressure) {+    const writer = stream[writer_];+    if (writer !== undefined && backpressure !== stream[backpressure_]) {+        if (backpressure) {+            writer[readyPromise_] = createControlledPromise();+        }+        else {+            writer[readyPromise_].resolve(undefined);+        }+    }+    stream[backpressure_] = backpressure;+}+function isWritableStreamDefaultWriter(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return ownerWritableStream_ in value;+}+function writableStreamDefaultWriterAbort(writer, reason) {+    const stream = writer[ownerWritableStream_];+    return writableStreamAbort(stream, reason);+}+function writableStreamDefaultWriterClose(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return Promise.reject(new TypeError("Writer stream is already closed or errored"));+    }+    const closePromise = createControlledPromise();+    stream[closeRequest_] = closePromise;+    if (stream[backpressure_] && state === "writable") {+        writer[readyPromise_].resolve(undefined);+    }+    writableStreamDefaultControllerClose(stream[writableStreamController_]);+    return closePromise.promise;+}+function writableStreamDefaultWriterCloseWithErrorPropagation(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") {+        return Promise.resolve(undefined);+    }+    if (state === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return writableStreamDefaultWriterClose(writer);+}+function writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {+    const closedPromise = writer[closedPromise_$1];+    if (closedPromise.state === ControlledPromiseState.Pending) {+        closedPromise.reject(error);+    }+    else {+        writer[closedPromise_$1] = createControlledPromise();+        writer[closedPromise_$1].reject(error);+    }+    writer[closedPromise_$1].promise.catch(() => { });+}+function writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {+    const readyPromise = writer[readyPromise_];+    if (readyPromise.state === ControlledPromiseState.Pending) {+        readyPromise.reject(error);+    }+    else {+        writer[readyPromise_] = createControlledPromise();+        writer[readyPromise_].reject(error);+    }+    writer[readyPromise_].promise.catch(() => { });+}+function writableStreamDefaultWriterGetDesiredSize(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (state === "errored" || state === "erroring") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return writableStreamDefaultControllerGetDesiredSize(stream[writableStreamController_]);+}+function writableStreamDefaultWriterRelease(writer) {+    const stream = writer[ownerWritableStream_];+    const releasedError = new TypeError();+    writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);+    writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);+    stream[writer_] = undefined;+    writer[ownerWritableStream_] = undefined;+}+function writableStreamDefaultWriterWrite(writer, chunk) {+    const stream = writer[ownerWritableStream_];+    const controller = stream[writableStreamController_];+    const chunkSize = writableStreamDefaultControllerGetChunkSize(controller, chunk);+    if (writer[ownerWritableStream_] !== stream) {+        return Promise.reject(new TypeError());+    }+    const state = stream[state_];+    if (state === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") {+        return Promise.reject(new TypeError("Cannot write to a closing or closed stream"));+    }+    if (state === "erroring") {+        return Promise.reject(stream[storedError_]);+    }+    const promise = writableStreamAddWriteRequest(stream);+    writableStreamDefaultControllerWrite(controller, chunk, chunkSize);+    return promise;+}+function setUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {+    if (!isWritableStream(stream)) {+        throw new TypeError();+    }+    if (stream[writableStreamController_] !== undefined) {+        throw new TypeError();+    }+    controller[controlledWritableStream_] = stream;+    stream[writableStreamController_] = controller;+    resetQueue(controller);+    controller[started_$1] = false;+    controller[strategySizeAlgorithm_$1] = sizeAlgorithm;+    controller[strategyHWM_$1] = highWaterMark;+    controller[writeAlgorithm_] = writeAlgorithm;+    controller[closeAlgorithm_] = closeAlgorithm;+    controller[abortAlgorithm_] = abortAlgorithm;+    const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+    writableStreamUpdateBackpressure(stream, backpressure);+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_$1] = true;+        writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+    }, error => {+        controller[started_$1] = true;+        writableStreamDealWithRejection(stream, error);+    });+}+function isWritableStreamDefaultController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledWritableStream_ in value;+}+function writableStreamDefaultControllerClearAlgorithms(controller) {+    controller[writeAlgorithm_] = undefined;+    controller[closeAlgorithm_] = undefined;+    controller[abortAlgorithm_] = undefined;+    controller[strategySizeAlgorithm_$1] = undefined;+}+function writableStreamDefaultControllerClose(controller) {+    enqueueValueWithSize(controller, "close", 0);+    writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+}+function writableStreamDefaultControllerGetChunkSize(controller, chunk) {+    let chunkSize;+    try {+        chunkSize = controller[strategySizeAlgorithm_$1](chunk);+    }+    catch (error) {+        writableStreamDefaultControllerErrorIfNeeded(controller, error);+        chunkSize = 1;+    }+    return chunkSize;+}+function writableStreamDefaultControllerGetDesiredSize(controller) {+    return controller[strategyHWM_$1] - controller[queueTotalSize_];+}+function writableStreamDefaultControllerWrite(controller, chunk, chunkSize) {+    try {+        enqueueValueWithSize(controller, { chunk }, chunkSize);+    }+    catch (error) {+        writableStreamDefaultControllerErrorIfNeeded(controller, error);+        return;+    }+    const stream = controller[controlledWritableStream_];+    if (!writableStreamCloseQueuedOrInFlight(stream) && stream[state_] === "writable") {+        const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+        writableStreamUpdateBackpressure(stream, backpressure);+    }+    writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+}+function writableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {+    if (!controller[started_$1]) {+        return;+    }+    const stream = controller[controlledWritableStream_];+    if (stream[inFlightWriteRequest_] !== undefined) {+        return;+    }+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return;+    }+    if (state === "erroring") {+        writableStreamFinishErroring(stream);+        return;+    }+    if (controller[queue_].length === 0) {+        return;+    }+    const writeRecord = peekQueueValue(controller);+    if (writeRecord === "close") {+        writableStreamDefaultControllerProcessClose(controller);+    }+    else {+        writableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk);+    }+}+function writableStreamDefaultControllerErrorIfNeeded(controller, error) {+    if (controller[controlledWritableStream_][state_] === "writable") {+        writableStreamDefaultControllerError(controller, error);+    }+}+function writableStreamDefaultControllerProcessClose(controller) {+    const stream = controller[controlledWritableStream_];+    writableStreamMarkCloseRequestInFlight(stream);+    dequeueValue(controller);+    const sinkClosePromise = controller[closeAlgorithm_]();+    writableStreamDefaultControllerClearAlgorithms(controller);+    sinkClosePromise.then(_ => {+        writableStreamFinishInFlightClose(stream);+    }, error => {+        writableStreamFinishInFlightCloseWithError(stream, error);+    });+}+function writableStreamDefaultControllerProcessWrite(controller, chunk) {+    const stream = controller[controlledWritableStream_];+    writableStreamMarkFirstWriteRequestInFlight(stream);+    controller[writeAlgorithm_](chunk).then(_ => {+        writableStreamFinishInFlightWrite(stream);+        const state = stream[state_];+        dequeueValue(controller);+        if (!writableStreamCloseQueuedOrInFlight(stream) && state === "writable") {+            const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+            writableStreamUpdateBackpressure(stream, backpressure);+        }+        writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+    }, error => {+        if (stream[state_] === "writable") {+            writableStreamDefaultControllerClearAlgorithms(controller);+        }+        writableStreamFinishInFlightWriteWithError(stream, error);+    });+}+function writableStreamDefaultControllerGetBackpressure(controller) {+    const desiredSize = writableStreamDefaultControllerGetDesiredSize(controller);+    return desiredSize <= 0;+}+function writableStreamDefaultControllerError(controller, error) {+    const stream = controller[controlledWritableStream_];+    writableStreamDefaultControllerClearAlgorithms(controller);+    writableStreamStartErroring(stream, error);+}++class ReadableStreamDefaultReader {+    constructor(stream) {+        if (!isReadableStream(stream)) {+            throw new TypeError();+        }+        if (isReadableStreamLocked(stream)) {+            throw new TypeError("The stream is locked.");+        }+        readableStreamReaderGenericInitialize(this, stream);+        this[readRequests_] = [];+    }+    get closed() {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        return this[closedPromise_].promise;+    }+    cancel(reason) {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        const stream = this[ownerReadableStream_];+        if (stream === undefined) {+            return Promise.reject(new TypeError("Reader is not associated with a stream"));+        }+        return readableStreamCancel(stream, reason);+    }+    read() {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerReadableStream_] === undefined) {+            return Promise.reject(new TypeError("Reader is not associated with a stream"));+        }+        return readableStreamDefaultReaderRead(this, true);+    }+    releaseLock() {+        if (!isReadableStreamDefaultReader(this)) {+            throw new TypeError();+        }+        if (this[ownerReadableStream_] === undefined) {+            return;+        }+        if (this[readRequests_].length !== 0) {+            throw new TypeError("Cannot release a stream with pending read requests");+        }+        readableStreamReaderGenericRelease(this);+    }+}++class WritableStreamDefaultWriter {+    constructor(stream) {+        if (!isWritableStream(stream)) {+            throw new TypeError();+        }+        if (isWritableStreamLocked(stream)) {+            throw new TypeError("Stream is already locked");+        }+        this[ownerWritableStream_] = stream;+        stream[writer_] = this;+        const readyPromise = createControlledPromise();+        const closedPromise = createControlledPromise();+        this[readyPromise_] = readyPromise;+        this[closedPromise_$1] = closedPromise;+        const state = stream[state_];+        if (state === "writable") {+            if (!writableStreamCloseQueuedOrInFlight(stream) && stream[backpressure_]) ;+            else {+                readyPromise.resolve(undefined);+            }+        }+        else if (state === "erroring") {+            readyPromise.reject(stream[storedError_]);+            readyPromise.promise.catch(() => { });+        }+        else if (state === "closed") {+            readyPromise.resolve(undefined);+            closedPromise.resolve(undefined);+        }+        else {+            const storedError = stream[storedError_];+            readyPromise.reject(storedError);+            readyPromise.promise.catch(() => { });+            closedPromise.reject(storedError);+            closedPromise.promise.catch(() => { });+        }+    }+    abort(reason) {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerWritableStream_] === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        return writableStreamDefaultWriterAbort(this, reason);+    }+    close() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        const stream = this[ownerWritableStream_];+        if (stream === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        if (writableStreamCloseQueuedOrInFlight(stream)) {+            return Promise.reject(new TypeError());+        }+        return writableStreamDefaultWriterClose(this);+    }+    releaseLock() {+        const stream = this[ownerWritableStream_];+        if (stream === undefined) {+            return;+        }+        writableStreamDefaultWriterRelease(this);+    }+    write(chunk) {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerWritableStream_] === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        return writableStreamDefaultWriterWrite(this, chunk);+    }+    get closed() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        return this[closedPromise_$1].promise;+    }+    get desiredSize() {+        if (!isWritableStreamDefaultWriter(this)) {+            throw new TypeError();+        }+        if (this[ownerWritableStream_] === undefined) {+            throw new TypeError("Writer is not connected to stream");+        }+        return writableStreamDefaultWriterGetDesiredSize(this);+    }+    get ready() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        return this[readyPromise_].promise;+    }+}++function pipeTo(source, dest, options) {+    const preventClose = !!options.preventClose;+    const preventAbort = !!options.preventAbort;+    const preventCancel = !!options.preventCancel;+    const signal = options.signal;+    let shuttingDown = false;+    let latestWrite = Promise.resolve();+    const promise = createControlledPromise();+    const reader = new ReadableStreamDefaultReader(source);+    const writer = new WritableStreamDefaultWriter(dest);+    let abortAlgorithm;+    if (signal !== undefined) {+        abortAlgorithm = () => {+            const error = new DOMException("Aborted", "AbortError");+            const actions = [];+            if (preventAbort === false) {+                actions.push(() => {+                    if (dest[state_] === "writable") {+                        return writableStreamAbort(dest, error);+                    }+                    return Promise.resolve();+                });+            }+            if (preventCancel === false) {+                actions.push(() => {+                    if (source[state_] === "readable") {+                        return readableStreamCancel(source, error);+                    }+                    return Promise.resolve();+                });+            }+            shutDown(() => {+                return Promise.all(actions.map(a => a())).then(_ => undefined);+            }, { actualError: error });+        };+        if (signal.aborted === true) {+            abortAlgorithm();+        }+        else {+            signal.addEventListener("abort", abortAlgorithm);+        }+    }+    function onStreamErrored(stream, promise, action) {+        if (stream[state_] === "errored") {+            action(stream[storedError_]);+        }+        else {+            promise.catch(action);+        }+    }+    function onStreamClosed(stream, promise, action) {+        if (stream[state_] === "closed") {+            action();+        }+        else {+            promise.then(action);+        }+    }+    onStreamErrored(source, reader[closedPromise_].promise, error => {+        if (!preventAbort) {+            shutDown(() => writableStreamAbort(dest, error), { actualError: error });+        }+        else {+            shutDown(undefined, { actualError: error });+        }+    });+    onStreamErrored(dest, writer[closedPromise_$1].promise, error => {+        if (!preventCancel) {+            shutDown(() => readableStreamCancel(source, error), { actualError: error });+        }+        else {+            shutDown(undefined, { actualError: error });+        }+    });+    onStreamClosed(source, reader[closedPromise_].promise, () => {+        if (!preventClose) {+            shutDown(() => writableStreamDefaultWriterCloseWithErrorPropagation(writer));+        }+        else {+            shutDown();+        }+    });+    if (writableStreamCloseQueuedOrInFlight(dest) || dest[state_] === "closed") {+        const destClosed = new TypeError();+        if (!preventCancel) {+            shutDown(() => readableStreamCancel(source, destClosed), { actualError: destClosed });+        }+        else {+            shutDown(undefined, { actualError: destClosed });+        }+    }+    function awaitLatestWrite() {+        const curLatestWrite = latestWrite;+        return latestWrite.then(() => curLatestWrite === latestWrite ? undefined : awaitLatestWrite());+    }+    function flushRemainder() {+        if (dest[state_] === "writable" && (!writableStreamCloseQueuedOrInFlight(dest))) {+            return awaitLatestWrite();+        }+        else {+            return undefined;+        }+    }+    function shutDown(action, error) {+        if (shuttingDown) {+            return;+        }+        shuttingDown = true;+        if (action === undefined) {+            action = () => Promise.resolve();+        }+        function finishShutDown() {+            action().then(_ => finalize(error), newError => finalize({ actualError: newError }));+        }+        const flushWait = flushRemainder();+        if (flushWait) {+            flushWait.then(finishShutDown);+        }+        else {+            finishShutDown();+        }+    }+    function finalize(error) {+        writableStreamDefaultWriterRelease(writer);+        readableStreamReaderGenericRelease(reader);+        if (signal && abortAlgorithm) {+            signal.removeEventListener("abort", abortAlgorithm);+        }+        if (error) {+            promise.reject(error.actualError);+        }+        else {+            promise.resolve(undefined);+        }+    }+    function next() {+        if (shuttingDown) {+            return;+        }+        writer[readyPromise_].promise.then(() => {+            readableStreamDefaultReaderRead(reader).then(({ value, done }) => {+                if (done) {+                    return;+                }+                latestWrite = writableStreamDefaultWriterWrite(writer, value).catch(() => { });+                next();+            }, _error => {+                latestWrite = Promise.resolve();+            });+        });+    }+    if (!shuttingDown) {+        next();+    }+    return promise.promise;+}++class ReadableStreamDefaultController {+    constructor() {+        throw new TypeError();+    }+    get desiredSize() {+        ret

I went ahead and moved that dependency to third_party.

mrkurt

comment created time in 20 days

pull request commentdenoland/deno

Global request / response

@kitsonk I added a new dependency to third_party and made a PR for it, it builds + passes when I use that branch: https://github.com/denoland/deno_third_party/pull/43

mrkurt

comment created time in 20 days

PR opened denoland/deno_third_party

adding @stardazed/streams js dependency

This is for https://github.com/denoland/deno/pull/2253

+5226 -0

0 comment

8 changed files

pr created time in 20 days

push eventsuperfly/deno_third_party

Kurt

commit sha 0ebecc9106270fbe9ae7748b1d6e8181315683e2

adding @stardazed/streams js dependency

view details

push time in 20 days

push eventsuperfly/deno

Kurt

commit sha 1a031f51b0a6c02cd253886f8e53a81a76e56af5

add a test case for `fetch(<Request>)`

view details

push time in 20 days

push eventsuperfly/deno

Kurt

commit sha f810aaeb36ce428ab468cbe687edd94bbf687bff

move sd-streams to thirdparty (needs pr over there)

view details

push time in 20 days

create barnchsuperfly/deno_third_party

branch : sd-streams

created branch time in 20 days

Pull request review commentdenoland/deno

Global request response

+/**+* @stardazed/streams - implementation of the web streams standard+* Part of Stardazed+* (c) 2018-Present by Arthur Langereis - @zenmumbler+* https://github.com/stardazed/sd-streams+*/++const state_ = Symbol("state_");+const storedError_ = Symbol("storedError_");+function isInteger(value) {+    if (!isFinite(value)) {+        return false;+    }+    const absValue = Math.abs(value);+    return Math.floor(absValue) === absValue;+}+function isFiniteNonNegativeNumber(value) {+    if (!(typeof value === "number" && isFinite(value))) {+        return false;+    }+    return value >= 0;+}+function isAbortSignal(signal) {+    if (typeof signal !== "object" || signal === null) {+        return false;+    }+    try {+        const aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, "aborted").get;+        aborted.call(signal);+        return true;+    }+    catch (err) {+        return false;+    }+}+function invokeOrNoop(o, p, args) {+    const method = o[p];+    if (method === undefined) {+        return undefined;+    }+    return Function.prototype.apply.call(method, o, args);+}+function cloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, cloneConstructor) {+    return srcBuffer.slice(srcByteOffset, srcByteOffset + srcLength);+}+function transferArrayBuffer(buffer) {+    return buffer.slice(0);+}+function copyDataBlockBytes(toBlock, toIndex, fromBlock, fromIndex, count) {+    new Uint8Array(toBlock, toIndex, count).set(new Uint8Array(fromBlock, fromIndex, count));+}+const objectCloneMemo = new WeakMap();+let sharedArrayBufferSupported_;+function supportsSharedArrayBuffer() {+    if (sharedArrayBufferSupported_ === undefined) {+        try {+            new SharedArrayBuffer(16);+            sharedArrayBufferSupported_ = true;+        }+        catch (e) {+            sharedArrayBufferSupported_ = false;+        }+    }+    return sharedArrayBufferSupported_;+}+function cloneValue(value) {+    const valueType = typeof value;+    switch (valueType) {+        case "number":+        case "string":+        case "boolean":+        case "undefined":+        case "bigint":+            return value;+        case "object": {+            if (objectCloneMemo.has(value)) {+                return objectCloneMemo.get(value);+            }+            if (value === null) {+                return value;+            }+            if (value instanceof Date) {+                return new Date(value.valueOf());+            }+            if (value instanceof RegExp) {+                return new RegExp(value);+            }+            if (supportsSharedArrayBuffer() && value instanceof SharedArrayBuffer) {+                return value;+            }+            if (value instanceof ArrayBuffer) {+                const cloned = cloneArrayBuffer(value, 0, value.byteLength, ArrayBuffer);+                objectCloneMemo.set(value, cloned);+                return cloned;+            }+            if (ArrayBuffer.isView(value)) {+                const clonedBuffer = cloneValue(value.buffer);+                let length;+                if (value instanceof DataView) {+                    length = value.byteLength;+                }+                else {+                    length = value.length;+                }+                return new value.constructor(clonedBuffer, value.byteOffset, length);+            }+            if (value instanceof Map) {+                const clonedMap = new Map();+                objectCloneMemo.set(value, clonedMap);+                value.forEach((v, k) => clonedMap.set(k, cloneValue(v)));+                return clonedMap;+            }+            if (value instanceof Set) {+                const clonedSet = new Map();+                objectCloneMemo.set(value, clonedSet);+                value.forEach((v, k) => clonedSet.set(k, cloneValue(v)));+                return clonedSet;+            }+            const clonedObj = {};+            objectCloneMemo.set(value, clonedObj);+            const sourceKeys = Object.getOwnPropertyNames(value);+            for (const key of sourceKeys) {+                clonedObj[key] = cloneValue(value[key]);+            }+            return clonedObj;+        }+        case "symbol":+        case "function":+        default:+            throw new DOMException("Uncloneable value in stream", "DataCloneError");+    }+}+function promiseCall(f, v, args) {+    try {+        const result = Function.prototype.apply.call(f, v, args);+        return Promise.resolve(result);+    }+    catch (err) {+        return Promise.reject(err);+    }+}+function createAlgorithmFromUnderlyingMethod(obj, methodName, extraArgs) {+    const method = obj[methodName];+    if (method === undefined) {+        return () => Promise.resolve(undefined);+    }+    if (typeof method !== "function") {+        throw new TypeError(`Field "${methodName}" is not a function.`);+    }+    return function (...fnArgs) {+        return promiseCall(method, obj, fnArgs.concat(extraArgs));+    };+}+function validateAndNormalizeHighWaterMark(hwm) {+    const highWaterMark = Number(hwm);+    if (isNaN(highWaterMark) || highWaterMark < 0) {+        throw new RangeError("highWaterMark must be a valid, non-negative integer.");+    }+    return highWaterMark;+}+function makeSizeAlgorithmFromSizeFunction(sizeFn) {+    if (typeof sizeFn !== "function" && typeof sizeFn !== "undefined") {+        throw new TypeError("size function must be undefined or a function");+    }+    return function (chunk) {+        if (typeof sizeFn === "function") {+            return sizeFn(chunk);+        }+        return 1;+    };+}+var ControlledPromiseState;+(function (ControlledPromiseState) {+    ControlledPromiseState[ControlledPromiseState["Pending"] = 0] = "Pending";+    ControlledPromiseState[ControlledPromiseState["Resolved"] = 1] = "Resolved";+    ControlledPromiseState[ControlledPromiseState["Rejected"] = 2] = "Rejected";+})(ControlledPromiseState || (ControlledPromiseState = {}));+function createControlledPromise() {+    const conProm = {+        state: ControlledPromiseState.Pending+    };+    conProm.promise = new Promise(function (resolve, reject) {+        conProm.resolve = function (v) { conProm.state = ControlledPromiseState.Resolved; resolve(v); };+        conProm.reject = function (e) { conProm.state = ControlledPromiseState.Rejected; reject(e); };+    });+    return conProm;+}++const CHUNK_SIZE = 16384;+class QueueImpl {+    constructor() {+        this.chunks_ = [[]];+        this.readChunk_ = this.writeChunk_ = this.chunks_[0];+        this.length_ = 0;+    }+    push(t) {+        this.writeChunk_.push(t);+        this.length_ += 1;+        if (this.writeChunk_.length === CHUNK_SIZE) {+            this.writeChunk_ = [];+            this.chunks_.push(this.writeChunk_);+        }+    }+    front() {+        if (this.length_ === 0) {+            return undefined;+        }+        return this.readChunk_[0];+    }+    shift() {+        if (this.length_ === 0) {+            return undefined;+        }+        const t = this.readChunk_.shift();+        this.length_ -= 1;+        if (this.readChunk_.length === 0 && this.readChunk_ !== this.writeChunk_) {+            this.chunks_.shift();+            this.readChunk_ = this.chunks_[0];+        }+        return t;+    }+    get length() {+        return this.length_;+    }+}++const queue_ = Symbol("queue_");+const queueTotalSize_ = Symbol("queueTotalSize_");+function dequeueValue(container) {+    const pair = container[queue_].shift();+    const newTotalSize = container[queueTotalSize_] - pair.size;+    container[queueTotalSize_] = Math.max(0, newTotalSize);+    return pair.value;+}+function enqueueValueWithSize(container, value, size) {+    if (!isFiniteNonNegativeNumber(size)) {+        throw new RangeError("Chunk size must be a non-negative, finite numbers");+    }+    container[queue_].push({ value, size });+    container[queueTotalSize_] += size;+}+function peekQueueValue(container) {+    return container[queue_].front().value;+}+function resetQueue(container) {+    container[queue_] = new QueueImpl();+    container[queueTotalSize_] = 0;+}++const controlledReadableStream_ = Symbol("controlledReadableStream_");+const pullAlgorithm_ = Symbol("pullAlgorithm_");+const cancelAlgorithm_ = Symbol("cancelAlgorithm_");+const strategySizeAlgorithm_ = Symbol("strategySizeAlgorithm_");+const strategyHWM_ = Symbol("strategyHWM_");+const started_ = Symbol("started_");+const closeRequested_ = Symbol("closeRequested_");+const pullAgain_ = Symbol("pullAgain_");+const pulling_ = Symbol("pulling_");+const cancelSteps_ = Symbol("cancelSteps_");+const pullSteps_ = Symbol("pullSteps_");+const autoAllocateChunkSize_ = Symbol("autoAllocateChunkSize_");+const byobRequest_ = Symbol("byobRequest_");+const controlledReadableByteStream_ = Symbol("controlledReadableByteStream_");+const pendingPullIntos_ = Symbol("pendingPullIntos_");+const closedPromise_ = Symbol("closedPromise_");+const ownerReadableStream_ = Symbol("ownerReadableStream_");+const readRequests_ = Symbol("readRequests_");+const readIntoRequests_ = Symbol("readIntoRequests_");+const associatedReadableByteStreamController_ = Symbol("associatedReadableByteStreamController_");+const view_ = Symbol("view_");+const reader_ = Symbol("reader_");+const readableStreamController_ = Symbol("readableStreamController_");+function initializeReadableStream(stream) {+    stream[state_] = "readable";+    stream[reader_] = undefined;+    stream[storedError_] = undefined;+    stream[readableStreamController_] = undefined;+}+function isReadableStream(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return readableStreamController_ in value;+}+function isReadableStreamLocked(stream) {+    return stream[reader_] !== undefined;+}+function readableStreamGetNumReadIntoRequests(stream) {+    const reader = stream[reader_];+    if (reader === undefined) {+        return 0;+    }+    return reader[readIntoRequests_].length;+}+function readableStreamGetNumReadRequests(stream) {+    const reader = stream[reader_];+    if (reader === undefined) {+        return 0;+    }+    return reader[readRequests_].length;+}+function readableStreamCreateReadResult(value, done, forAuthorCode) {+    const prototype = forAuthorCode ? Object.prototype : null;+    const result = Object.create(prototype);+    result.value = value;+    result.done = done;+    return result;+}+function readableStreamAddReadIntoRequest(stream, forAuthorCode) {+    const reader = stream[reader_];+    const conProm = createControlledPromise();+    conProm.forAuthorCode = forAuthorCode;+    reader[readIntoRequests_].push(conProm);+    return conProm.promise;+}+function readableStreamAddReadRequest(stream, forAuthorCode) {+    const reader = stream[reader_];+    const conProm = createControlledPromise();+    conProm.forAuthorCode = forAuthorCode;+    reader[readRequests_].push(conProm);+    return conProm.promise;+}+function readableStreamHasBYOBReader(stream) {+    const reader = stream[reader_];+    return isReadableStreamBYOBReader(reader);+}+function readableStreamHasDefaultReader(stream) {+    const reader = stream[reader_];+    return isReadableStreamDefaultReader(reader);+}+function readableStreamCancel(stream, reason) {+    if (stream[state_] === "closed") {+        return Promise.resolve(undefined);+    }+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    readableStreamClose(stream);+    const sourceCancelPromise = stream[readableStreamController_][cancelSteps_](reason);+    return sourceCancelPromise.then(_ => undefined);+}+function readableStreamClose(stream) {+    stream[state_] = "closed";+    const reader = stream[reader_];+    if (reader === undefined) {+        return;+    }+    if (isReadableStreamDefaultReader(reader)) {+        for (const readRequest of reader[readRequests_]) {+            readRequest.resolve(readableStreamCreateReadResult(undefined, true, readRequest.forAuthorCode));+        }+        reader[readRequests_] = [];+    }+    reader[closedPromise_].resolve();+    reader[closedPromise_].promise.catch(() => { });+}+function readableStreamError(stream, error) {+    if (stream[state_] !== "readable") {+        throw new RangeError("Stream is in an invalid state");+    }+    stream[state_] = "errored";+    stream[storedError_] = error;+    const reader = stream[reader_];+    if (reader === undefined) {+        return;+    }+    if (isReadableStreamDefaultReader(reader)) {+        for (const readRequest of reader[readRequests_]) {+            readRequest.reject(error);+        }+        reader[readRequests_] = [];+    }+    else {+        const readIntoRequests = reader[readIntoRequests_];+        for (const readIntoRequest of readIntoRequests) {+            readIntoRequest.reject(error);+        }+        reader[readIntoRequests_] = [];+    }+    reader[closedPromise_].reject(error);+}+function isReadableStreamDefaultReader(reader) {+    if (typeof reader !== "object" || reader === null) {+        return false;+    }+    return readRequests_ in reader;+}+function isReadableStreamBYOBReader(reader) {+    if (typeof reader !== "object" || reader === null) {+        return false;+    }+    return readIntoRequests_ in reader;+}+function readableStreamReaderGenericInitialize(reader, stream) {+    reader[ownerReadableStream_] = stream;+    stream[reader_] = reader;+    const streamState = stream[state_];+    reader[closedPromise_] = createControlledPromise();+    if (streamState === "readable") ;+    else if (streamState === "closed") {+        reader[closedPromise_].resolve(undefined);+    }+    else {+        reader[closedPromise_].reject(stream[storedError_]);+        reader[closedPromise_].promise.catch(() => { });+    }+}+function readableStreamReaderGenericRelease(reader) {+    const stream = reader[ownerReadableStream_];+    if (stream === undefined) {+        throw new TypeError("Reader is in an inconsistent state");+    }+    if (stream[state_] === "readable") ;+    else {+        reader[closedPromise_] = createControlledPromise();+    }+    reader[closedPromise_].reject(new TypeError());+    reader[closedPromise_].promise.catch(() => { });+    stream[reader_] = undefined;+    reader[ownerReadableStream_] = undefined;+}+function readableStreamBYOBReaderRead(reader, view, forAuthorCode = false) {+    const stream = reader[ownerReadableStream_];+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return readableByteStreamControllerPullInto(stream[readableStreamController_], view, forAuthorCode);+}+function readableStreamDefaultReaderRead(reader, forAuthorCode = false) {+    const stream = reader[ownerReadableStream_];+    if (stream[state_] === "closed") {+        return Promise.resolve(readableStreamCreateReadResult(undefined, true, forAuthorCode));+    }+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return stream[readableStreamController_][pullSteps_](forAuthorCode);+}+function readableStreamFulfillReadIntoRequest(stream, chunk, done) {+    const reader = stream[reader_];+    const readIntoRequest = reader[readIntoRequests_].shift();+    readIntoRequest.resolve(readableStreamCreateReadResult(chunk, done, readIntoRequest.forAuthorCode));+}+function readableStreamFulfillReadRequest(stream, chunk, done) {+    const reader = stream[reader_];+    const readRequest = reader[readRequests_].shift();+    readRequest.resolve(readableStreamCreateReadResult(chunk, done, readRequest.forAuthorCode));+}+function setUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {+    controller[controlledReadableStream_] = stream;+    resetQueue(controller);+    controller[started_] = false;+    controller[closeRequested_] = false;+    controller[pullAgain_] = false;+    controller[pulling_] = false;+    controller[strategySizeAlgorithm_] = sizeAlgorithm;+    controller[strategyHWM_] = highWaterMark;+    controller[pullAlgorithm_] = pullAlgorithm;+    controller[cancelAlgorithm_] = cancelAlgorithm;+    stream[readableStreamController_] = controller;+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_] = true;+        readableStreamDefaultControllerCallPullIfNeeded(controller);+    }, error => {+        readableStreamDefaultControllerError(controller, error);+    });+}+function isReadableStreamDefaultController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledReadableStream_ in value;+}+function readableStreamDefaultControllerHasBackpressure(controller) {+    return !readableStreamDefaultControllerShouldCallPull(controller);+}+function readableStreamDefaultControllerCanCloseOrEnqueue(controller) {+    const state = controller[controlledReadableStream_][state_];+    return controller[closeRequested_] === false && state === "readable";+}+function readableStreamDefaultControllerGetDesiredSize(controller) {+    const state = controller[controlledReadableStream_][state_];+    if (state === "errored") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return controller[strategyHWM_] - controller[queueTotalSize_];+}+function readableStreamDefaultControllerClose(controller) {+    controller[closeRequested_] = true;+    const stream = controller[controlledReadableStream_];+    if (controller[queue_].length === 0) {+        readableStreamDefaultControllerClearAlgorithms(controller);+        readableStreamClose(stream);+    }+}+function readableStreamDefaultControllerEnqueue(controller, chunk) {+    const stream = controller[controlledReadableStream_];+    if (isReadableStreamLocked(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        readableStreamFulfillReadRequest(stream, chunk, false);+    }+    else {+        let chunkSize;+        try {+            chunkSize = controller[strategySizeAlgorithm_](chunk);+        }+        catch (error) {+            readableStreamDefaultControllerError(controller, error);+            throw error;+        }+        try {+            enqueueValueWithSize(controller, chunk, chunkSize);+        }+        catch (error) {+            readableStreamDefaultControllerError(controller, error);+            throw error;+        }+    }+    readableStreamDefaultControllerCallPullIfNeeded(controller);+}+function readableStreamDefaultControllerError(controller, error) {+    const stream = controller[controlledReadableStream_];+    if (stream[state_] !== "readable") {+        return;+    }+    resetQueue(controller);+    readableStreamDefaultControllerClearAlgorithms(controller);+    readableStreamError(stream, error);+}+function readableStreamDefaultControllerCallPullIfNeeded(controller) {+    if (!readableStreamDefaultControllerShouldCallPull(controller)) {+        return;+    }+    if (controller[pulling_]) {+        controller[pullAgain_] = true;+        return;+    }+    if (controller[pullAgain_]) {+        throw new RangeError("Stream controller is in an invalid state.");+    }+    controller[pulling_] = true;+    controller[pullAlgorithm_](controller).then(_ => {+        controller[pulling_] = false;+        if (controller[pullAgain_]) {+            controller[pullAgain_] = false;+            readableStreamDefaultControllerCallPullIfNeeded(controller);+        }+    }, error => {+        readableStreamDefaultControllerError(controller, error);+    });+}+function readableStreamDefaultControllerShouldCallPull(controller) {+    const stream = controller[controlledReadableStream_];+    if (!readableStreamDefaultControllerCanCloseOrEnqueue(controller)) {+        return false;+    }+    if (controller[started_] === false) {+        return false;+    }+    if (isReadableStreamLocked(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        return true;+    }+    const desiredSize = readableStreamDefaultControllerGetDesiredSize(controller);+    if (desiredSize === null) {+        throw new RangeError("Stream is in an invalid state.");+    }+    return desiredSize > 0;+}+function readableStreamDefaultControllerClearAlgorithms(controller) {+    controller[pullAlgorithm_] = undefined;+    controller[cancelAlgorithm_] = undefined;+    controller[strategySizeAlgorithm_] = undefined;+}+function setUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {+    if (stream[readableStreamController_] !== undefined) {+        throw new TypeError("Cannot reuse streams");+    }+    if (autoAllocateChunkSize !== undefined) {+        if (!isInteger(autoAllocateChunkSize) || autoAllocateChunkSize <= 0) {+            throw new RangeError("autoAllocateChunkSize must be a positive, finite integer");+        }+    }+    controller[controlledReadableByteStream_] = stream;+    controller[pullAgain_] = false;+    controller[pulling_] = false;+    readableByteStreamControllerClearPendingPullIntos(controller);+    resetQueue(controller);+    controller[closeRequested_] = false;+    controller[started_] = false;+    controller[strategyHWM_] = validateAndNormalizeHighWaterMark(highWaterMark);+    controller[pullAlgorithm_] = pullAlgorithm;+    controller[cancelAlgorithm_] = cancelAlgorithm;+    controller[autoAllocateChunkSize_] = autoAllocateChunkSize;+    controller[pendingPullIntos_] = [];+    stream[readableStreamController_] = controller;+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_] = true;+        readableByteStreamControllerCallPullIfNeeded(controller);+    }, error => {+        readableByteStreamControllerError(controller, error);+    });+}+function isReadableStreamBYOBRequest(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return associatedReadableByteStreamController_ in value;+}+function isReadableByteStreamController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledReadableByteStream_ in value;+}+function readableByteStreamControllerCallPullIfNeeded(controller) {+    if (!readableByteStreamControllerShouldCallPull(controller)) {+        return;+    }+    if (controller[pulling_]) {+        controller[pullAgain_] = true;+        return;+    }+    controller[pulling_] = true;+    controller[pullAlgorithm_](controller).then(_ => {+        controller[pulling_] = false;+        if (controller[pullAgain_]) {+            controller[pullAgain_] = false;+            readableByteStreamControllerCallPullIfNeeded(controller);+        }+    }, error => {+        readableByteStreamControllerError(controller, error);+    });+}+function readableByteStreamControllerClearAlgorithms(controller) {+    controller[pullAlgorithm_] = undefined;+    controller[cancelAlgorithm_] = undefined;+}+function readableByteStreamControllerClearPendingPullIntos(controller) {+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    controller[pendingPullIntos_] = [];+}+function readableByteStreamControllerClose(controller) {+    const stream = controller[controlledReadableByteStream_];+    if (controller[queueTotalSize_] > 0) {+        controller[closeRequested_] = true;+        return;+    }+    if (controller[pendingPullIntos_].length > 0) {+        const firstPendingPullInto = controller[pendingPullIntos_][0];+        if (firstPendingPullInto.bytesFilled > 0) {+            const error = new TypeError();+            readableByteStreamControllerError(controller, error);+            throw error;+        }+    }+    readableByteStreamControllerClearAlgorithms(controller);+    readableStreamClose(stream);+}+function readableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {+    let done = false;+    if (stream[state_] === "closed") {+        done = true;+    }+    const filledView = readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);+    if (pullIntoDescriptor.readerType === "default") {+        readableStreamFulfillReadRequest(stream, filledView, done);+    }+    else {+        readableStreamFulfillReadIntoRequest(stream, filledView, done);+    }+}+function readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {+    const { bytesFilled, elementSize } = pullIntoDescriptor;+    return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);+}+function readableByteStreamControllerEnqueue(controller, chunk) {+    const stream = controller[controlledReadableByteStream_];+    const { buffer, byteOffset, byteLength } = chunk;+    const transferredBuffer = transferArrayBuffer(buffer);+    if (readableStreamHasDefaultReader(stream)) {+        if (readableStreamGetNumReadRequests(stream) === 0) {+            readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+        }+        else {+            const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);+            readableStreamFulfillReadRequest(stream, transferredView, false);+        }+    }+    else if (readableStreamHasBYOBReader(stream)) {+        readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+        readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);+    }+    else {+        readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+    }+    readableByteStreamControllerCallPullIfNeeded(controller);+}+function readableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {+    controller[queue_].push({ buffer, byteOffset, byteLength });+    controller[queueTotalSize_] += byteLength;+}+function readableByteStreamControllerError(controller, error) {+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] !== "readable") {+        return;+    }+    readableByteStreamControllerClearPendingPullIntos(controller);+    resetQueue(controller);+    readableByteStreamControllerClearAlgorithms(controller);+    readableStreamError(stream, error);+}+function readableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    pullIntoDescriptor.bytesFilled += size;+}+function readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {+    const elementSize = pullIntoDescriptor.elementSize;+    const currentAlignedBytes = pullIntoDescriptor.bytesFilled - (pullIntoDescriptor.bytesFilled % elementSize);+    const maxBytesToCopy = Math.min(controller[queueTotalSize_], pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);+    const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;+    const maxAlignedBytes = maxBytesFilled - (maxBytesFilled % elementSize);+    let totalBytesToCopyRemaining = maxBytesToCopy;+    let ready = false;+    if (maxAlignedBytes > currentAlignedBytes) {+        totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;+        ready = true;+    }+    const queue = controller[queue_];+    while (totalBytesToCopyRemaining > 0) {+        const headOfQueue = queue.front();+        const bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);+        const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;+        copyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);+        if (headOfQueue.byteLength === bytesToCopy) {+            queue.shift();+        }+        else {+            headOfQueue.byteOffset += bytesToCopy;+            headOfQueue.byteLength -= bytesToCopy;+        }+        controller[queueTotalSize_] -= bytesToCopy;+        readableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);+        totalBytesToCopyRemaining -= bytesToCopy;+    }+    return ready;+}+function readableByteStreamControllerGetDesiredSize(controller) {+    const stream = controller[controlledReadableByteStream_];+    const state = stream[state_];+    if (state === "errored") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return controller[strategyHWM_] - controller[queueTotalSize_];+}+function readableByteStreamControllerHandleQueueDrain(controller) {+    if (controller[queueTotalSize_] === 0 && controller[closeRequested_]) {+        readableByteStreamControllerClearAlgorithms(controller);+        readableStreamClose(controller[controlledReadableByteStream_]);+    }+    else {+        readableByteStreamControllerCallPullIfNeeded(controller);+    }+}+function readableByteStreamControllerInvalidateBYOBRequest(controller) {+    const byobRequest = controller[byobRequest_];+    if (byobRequest === undefined) {+        return;+    }+    byobRequest[associatedReadableByteStreamController_] = undefined;+    byobRequest[view_] = undefined;+    controller[byobRequest_] = undefined;+}+function readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {+    const pendingPullIntos = controller[pendingPullIntos_];+    while (pendingPullIntos.length > 0) {+        if (controller[queueTotalSize_] === 0) {+            return;+        }+        const pullIntoDescriptor = pendingPullIntos[0];+        if (readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {+            readableByteStreamControllerShiftPendingPullInto(controller);+            readableByteStreamControllerCommitPullIntoDescriptor(controller[controlledReadableByteStream_], pullIntoDescriptor);+        }+    }+}+function readableByteStreamControllerPullInto(controller, view, forAuthorCode) {+    const stream = controller[controlledReadableByteStream_];+    const elementSize = view.BYTES_PER_ELEMENT || 1;+    const ctor = view.constructor;+    const byteOffset = view.byteOffset;+    const byteLength = view.byteLength;+    const buffer = transferArrayBuffer(view.buffer);+    const pullIntoDescriptor = { buffer, byteOffset, byteLength, bytesFilled: 0, elementSize, ctor, readerType: "byob" };+    if (controller[pendingPullIntos_].length > 0) {+        controller[pendingPullIntos_].push(pullIntoDescriptor);+        return readableStreamAddReadIntoRequest(stream, forAuthorCode);+    }+    if (stream[state_] === "closed") {+        const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);+        return Promise.resolve(readableStreamCreateReadResult(emptyView, true, forAuthorCode));+    }+    if (controller[queueTotalSize_] > 0) {+        if (readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {+            const filledView = readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);+            readableByteStreamControllerHandleQueueDrain(controller);+            return Promise.resolve(readableStreamCreateReadResult(filledView, false, forAuthorCode));+        }+        if (controller[closeRequested_]) {+            const error = new TypeError();+            readableByteStreamControllerError(controller, error);+            return Promise.reject(error);+        }+    }+    controller[pendingPullIntos_].push(pullIntoDescriptor);+    const promise = readableStreamAddReadIntoRequest(stream, forAuthorCode);+    readableByteStreamControllerCallPullIfNeeded(controller);+    return promise;+}+function readableByteStreamControllerRespond(controller, bytesWritten) {+    bytesWritten = Number(bytesWritten);+    if (!isFiniteNonNegativeNumber(bytesWritten)) {+        throw new RangeError("bytesWritten must be a finite, non-negative number");+    }+    readableByteStreamControllerRespondInternal(controller, bytesWritten);+}+function readableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {+    firstDescriptor.buffer = transferArrayBuffer(firstDescriptor.buffer);+    const stream = controller[controlledReadableByteStream_];+    if (readableStreamHasBYOBReader(stream)) {+        while (readableStreamGetNumReadIntoRequests(stream) > 0) {+            const pullIntoDescriptor = readableByteStreamControllerShiftPendingPullInto(controller);+            readableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);+        }+    }+}+function readableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {+    if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {+        throw new RangeError();+    }+    readableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);+    if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {+        return;+    }+    readableByteStreamControllerShiftPendingPullInto(controller);+    const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;+    if (remainderSize > 0) {+        const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;+        const remainder = cloneArrayBuffer(pullIntoDescriptor.buffer, end - remainderSize, remainderSize, ArrayBuffer);+        readableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);+    }+    pullIntoDescriptor.buffer = transferArrayBuffer(pullIntoDescriptor.buffer);+    pullIntoDescriptor.bytesFilled = pullIntoDescriptor.bytesFilled - remainderSize;+    readableByteStreamControllerCommitPullIntoDescriptor(controller[controlledReadableByteStream_], pullIntoDescriptor);+    readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);+}+function readableByteStreamControllerRespondInternal(controller, bytesWritten) {+    const firstDescriptor = controller[pendingPullIntos_][0];+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] === "closed") {+        if (bytesWritten !== 0) {+            throw new TypeError();+        }+        readableByteStreamControllerRespondInClosedState(controller, firstDescriptor);+    }+    else {+        readableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);+    }+    readableByteStreamControllerCallPullIfNeeded(controller);+}+function readableByteStreamControllerRespondWithNewView(controller, view) {+    const firstDescriptor = controller[pendingPullIntos_][0];+    if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {+        throw new RangeError();+    }+    if (firstDescriptor.byteLength !== view.byteLength) {+        throw new RangeError();+    }+    firstDescriptor.buffer = view.buffer;+    readableByteStreamControllerRespondInternal(controller, view.byteLength);+}+function readableByteStreamControllerShiftPendingPullInto(controller) {+    const descriptor = controller[pendingPullIntos_].shift();+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    return descriptor;+}+function readableByteStreamControllerShouldCallPull(controller) {+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] !== "readable") {+        return false;+    }+    if (controller[closeRequested_]) {+        return false;+    }+    if (!controller[started_]) {+        return false;+    }+    if (readableStreamHasDefaultReader(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        return true;+    }+    if (readableStreamHasBYOBReader(stream) && readableStreamGetNumReadIntoRequests(stream) > 0) {+        return true;+    }+    const desiredSize = readableByteStreamControllerGetDesiredSize(controller);+    return desiredSize > 0;+}+function setUpReadableStreamBYOBRequest(request, controller, view) {+    if (!isReadableByteStreamController(controller)) {+        throw new TypeError();+    }+    if (!ArrayBuffer.isView(view)) {+        throw new TypeError();+    }+    request[associatedReadableByteStreamController_] = controller;+    request[view_] = view;+}++const backpressure_ = Symbol("backpressure_");+const closeRequest_ = Symbol("closeRequest_");+const inFlightWriteRequest_ = Symbol("inFlightWriteRequest_");+const inFlightCloseRequest_ = Symbol("inFlightCloseRequest_");+const pendingAbortRequest_ = Symbol("pendingAbortRequest_");+const writableStreamController_ = Symbol("writableStreamController_");+const writer_ = Symbol("writer_");+const writeRequests_ = Symbol("writeRequests_");+const abortAlgorithm_ = Symbol("abortAlgorithm_");+const closeAlgorithm_ = Symbol("closeAlgorithm_");+const controlledWritableStream_ = Symbol("controlledWritableStream_");+const started_$1 = Symbol("started_");+const strategyHWM_$1 = Symbol("strategyHWM_");+const strategySizeAlgorithm_$1 = Symbol("strategySizeAlgorithm_");+const writeAlgorithm_ = Symbol("writeAlgorithm_");+const ownerWritableStream_ = Symbol("ownerWritableStream_");+const closedPromise_$1 = Symbol("closedPromise_");+const readyPromise_ = Symbol("readyPromise_");+const errorSteps_ = Symbol("errorSteps_");+const abortSteps_ = Symbol("abortSteps_");+function initializeWritableStream(stream) {+    stream[state_] = "writable";+    stream[storedError_] = undefined;+    stream[writer_] = undefined;+    stream[writableStreamController_] = undefined;+    stream[inFlightWriteRequest_] = undefined;+    stream[closeRequest_] = undefined;+    stream[inFlightCloseRequest_] = undefined;+    stream[pendingAbortRequest_] = undefined;+    stream[writeRequests_] = [];+    stream[backpressure_] = false;+}+function isWritableStream(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return writableStreamController_ in value;+}+function isWritableStreamLocked(stream) {+    return stream[writer_] !== undefined;+}+function writableStreamAbort(stream, reason) {+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return Promise.resolve(undefined);+    }+    let pending = stream[pendingAbortRequest_];+    if (pending !== undefined) {+        return pending.promise;+    }+    let wasAlreadyErroring = false;+    if (state === "erroring") {+        wasAlreadyErroring = true;+        reason = undefined;+    }+    pending = {+        reason,+        wasAlreadyErroring+    };+    const promise = new Promise((resolve, reject) => {+        pending.resolve = resolve;+        pending.reject = reject;+    });+    pending.promise = promise;+    stream[pendingAbortRequest_] = pending;+    if (!wasAlreadyErroring) {+        writableStreamStartErroring(stream, reason);+    }+    return promise;+}+function writableStreamAddWriteRequest(stream) {+    const writePromise = createControlledPromise();+    stream[writeRequests_].push(writePromise);+    return writePromise.promise;+}+function writableStreamDealWithRejection(stream, error) {+    const state = stream[state_];+    if (state === "writable") {+        writableStreamStartErroring(stream, error);+        return;+    }+    writableStreamFinishErroring(stream);+}+function writableStreamStartErroring(stream, reason) {+    const controller = stream[writableStreamController_];+    stream[state_] = "erroring";+    stream[storedError_] = reason;+    const writer = stream[writer_];+    if (writer !== undefined) {+        writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);+    }+    if (!writableStreamHasOperationMarkedInFlight(stream) && controller[started_$1]) {+        writableStreamFinishErroring(stream);+    }+}+function writableStreamFinishErroring(stream) {+    stream[state_] = "errored";+    const controller = stream[writableStreamController_];+    controller[errorSteps_]();+    const storedError = stream[storedError_];+    for (const writeRequest of stream[writeRequests_]) {+        writeRequest.reject(storedError);+    }+    stream[writeRequests_] = [];+    const abortRequest = stream[pendingAbortRequest_];+    if (abortRequest === undefined) {+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+        return;+    }+    stream[pendingAbortRequest_] = undefined;+    if (abortRequest.wasAlreadyErroring) {+        abortRequest.reject(storedError);+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+        return;+    }+    const promise = controller[abortSteps_](abortRequest.reason);+    promise.then(_ => {+        abortRequest.resolve();+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+    }, error => {+        abortRequest.reject(error);+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+    });+}+function writableStreamFinishInFlightWrite(stream) {+    stream[inFlightWriteRequest_].resolve(undefined);+    stream[inFlightWriteRequest_] = undefined;+}+function writableStreamFinishInFlightWriteWithError(stream, error) {+    stream[inFlightWriteRequest_].reject(error);+    stream[inFlightWriteRequest_] = undefined;+    writableStreamDealWithRejection(stream, error);+}+function writableStreamFinishInFlightClose(stream) {+    stream[inFlightCloseRequest_].resolve(undefined);+    stream[inFlightCloseRequest_] = undefined;+    const state = stream[state_];+    if (state === "erroring") {+        stream[storedError_] = undefined;+        if (stream[pendingAbortRequest_] !== undefined) {+            stream[pendingAbortRequest_].resolve();+            stream[pendingAbortRequest_] = undefined;+        }+    }+    stream[state_] = "closed";+    const writer = stream[writer_];+    if (writer !== undefined) {+        writer[closedPromise_$1].resolve(undefined);+    }+}+function writableStreamFinishInFlightCloseWithError(stream, error) {+    stream[inFlightCloseRequest_].reject(error);+    stream[inFlightCloseRequest_] = undefined;+    if (stream[pendingAbortRequest_] !== undefined) {+        stream[pendingAbortRequest_].reject(error);+        stream[pendingAbortRequest_] = undefined;+    }+    writableStreamDealWithRejection(stream, error);+}+function writableStreamCloseQueuedOrInFlight(stream) {+    return (stream[closeRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined);+}+function writableStreamHasOperationMarkedInFlight(stream) {+    return stream[inFlightWriteRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined;+}+function writableStreamMarkCloseRequestInFlight(stream) {+    stream[inFlightCloseRequest_] = stream[closeRequest_];+    stream[closeRequest_] = undefined;+}+function writableStreamMarkFirstWriteRequestInFlight(stream) {+    const writeRequest = stream[writeRequests_].shift();+    stream[inFlightWriteRequest_] = writeRequest;+}+function writableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {+    const closeRequest = stream[closeRequest_];+    if (closeRequest !== undefined) {+        closeRequest.reject(stream[storedError_]);+        stream[closeRequest_] = undefined;+    }+    const writer = stream[writer_];+    if (writer !== undefined) {+        writer[closedPromise_$1].reject(stream[storedError_]);+        writer[closedPromise_$1].promise.catch(() => { });+    }+}+function writableStreamUpdateBackpressure(stream, backpressure) {+    const writer = stream[writer_];+    if (writer !== undefined && backpressure !== stream[backpressure_]) {+        if (backpressure) {+            writer[readyPromise_] = createControlledPromise();+        }+        else {+            writer[readyPromise_].resolve(undefined);+        }+    }+    stream[backpressure_] = backpressure;+}+function isWritableStreamDefaultWriter(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return ownerWritableStream_ in value;+}+function writableStreamDefaultWriterAbort(writer, reason) {+    const stream = writer[ownerWritableStream_];+    return writableStreamAbort(stream, reason);+}+function writableStreamDefaultWriterClose(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return Promise.reject(new TypeError("Writer stream is already closed or errored"));+    }+    const closePromise = createControlledPromise();+    stream[closeRequest_] = closePromise;+    if (stream[backpressure_] && state === "writable") {+        writer[readyPromise_].resolve(undefined);+    }+    writableStreamDefaultControllerClose(stream[writableStreamController_]);+    return closePromise.promise;+}+function writableStreamDefaultWriterCloseWithErrorPropagation(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") {+        return Promise.resolve(undefined);+    }+    if (state === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return writableStreamDefaultWriterClose(writer);+}+function writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {+    const closedPromise = writer[closedPromise_$1];+    if (closedPromise.state === ControlledPromiseState.Pending) {+        closedPromise.reject(error);+    }+    else {+        writer[closedPromise_$1] = createControlledPromise();+        writer[closedPromise_$1].reject(error);+    }+    writer[closedPromise_$1].promise.catch(() => { });+}+function writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {+    const readyPromise = writer[readyPromise_];+    if (readyPromise.state === ControlledPromiseState.Pending) {+        readyPromise.reject(error);+    }+    else {+        writer[readyPromise_] = createControlledPromise();+        writer[readyPromise_].reject(error);+    }+    writer[readyPromise_].promise.catch(() => { });+}+function writableStreamDefaultWriterGetDesiredSize(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (state === "errored" || state === "erroring") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return writableStreamDefaultControllerGetDesiredSize(stream[writableStreamController_]);+}+function writableStreamDefaultWriterRelease(writer) {+    const stream = writer[ownerWritableStream_];+    const releasedError = new TypeError();+    writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);+    writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);+    stream[writer_] = undefined;+    writer[ownerWritableStream_] = undefined;+}+function writableStreamDefaultWriterWrite(writer, chunk) {+    const stream = writer[ownerWritableStream_];+    const controller = stream[writableStreamController_];+    const chunkSize = writableStreamDefaultControllerGetChunkSize(controller, chunk);+    if (writer[ownerWritableStream_] !== stream) {+        return Promise.reject(new TypeError());+    }+    const state = stream[state_];+    if (state === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") {+        return Promise.reject(new TypeError("Cannot write to a closing or closed stream"));+    }+    if (state === "erroring") {+        return Promise.reject(stream[storedError_]);+    }+    const promise = writableStreamAddWriteRequest(stream);+    writableStreamDefaultControllerWrite(controller, chunk, chunkSize);+    return promise;+}+function setUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {+    if (!isWritableStream(stream)) {+        throw new TypeError();+    }+    if (stream[writableStreamController_] !== undefined) {+        throw new TypeError();+    }+    controller[controlledWritableStream_] = stream;+    stream[writableStreamController_] = controller;+    resetQueue(controller);+    controller[started_$1] = false;+    controller[strategySizeAlgorithm_$1] = sizeAlgorithm;+    controller[strategyHWM_$1] = highWaterMark;+    controller[writeAlgorithm_] = writeAlgorithm;+    controller[closeAlgorithm_] = closeAlgorithm;+    controller[abortAlgorithm_] = abortAlgorithm;+    const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+    writableStreamUpdateBackpressure(stream, backpressure);+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_$1] = true;+        writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+    }, error => {+        controller[started_$1] = true;+        writableStreamDealWithRejection(stream, error);+    });+}+function isWritableStreamDefaultController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledWritableStream_ in value;+}+function writableStreamDefaultControllerClearAlgorithms(controller) {+    controller[writeAlgorithm_] = undefined;+    controller[closeAlgorithm_] = undefined;+    controller[abortAlgorithm_] = undefined;+    controller[strategySizeAlgorithm_$1] = undefined;+}+function writableStreamDefaultControllerClose(controller) {+    enqueueValueWithSize(controller, "close", 0);+    writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+}+function writableStreamDefaultControllerGetChunkSize(controller, chunk) {+    let chunkSize;+    try {+        chunkSize = controller[strategySizeAlgorithm_$1](chunk);+    }+    catch (error) {+        writableStreamDefaultControllerErrorIfNeeded(controller, error);+        chunkSize = 1;+    }+    return chunkSize;+}+function writableStreamDefaultControllerGetDesiredSize(controller) {+    return controller[strategyHWM_$1] - controller[queueTotalSize_];+}+function writableStreamDefaultControllerWrite(controller, chunk, chunkSize) {+    try {+        enqueueValueWithSize(controller, { chunk }, chunkSize);+    }+    catch (error) {+        writableStreamDefaultControllerErrorIfNeeded(controller, error);+        return;+    }+    const stream = controller[controlledWritableStream_];+    if (!writableStreamCloseQueuedOrInFlight(stream) && stream[state_] === "writable") {+        const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+        writableStreamUpdateBackpressure(stream, backpressure);+    }+    writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+}+function writableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {+    if (!controller[started_$1]) {+        return;+    }+    const stream = controller[controlledWritableStream_];+    if (stream[inFlightWriteRequest_] !== undefined) {+        return;+    }+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return;+    }+    if (state === "erroring") {+        writableStreamFinishErroring(stream);+        return;+    }+    if (controller[queue_].length === 0) {+        return;+    }+    const writeRecord = peekQueueValue(controller);+    if (writeRecord === "close") {+        writableStreamDefaultControllerProcessClose(controller);+    }+    else {+        writableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk);+    }+}+function writableStreamDefaultControllerErrorIfNeeded(controller, error) {+    if (controller[controlledWritableStream_][state_] === "writable") {+        writableStreamDefaultControllerError(controller, error);+    }+}+function writableStreamDefaultControllerProcessClose(controller) {+    const stream = controller[controlledWritableStream_];+    writableStreamMarkCloseRequestInFlight(stream);+    dequeueValue(controller);+    const sinkClosePromise = controller[closeAlgorithm_]();+    writableStreamDefaultControllerClearAlgorithms(controller);+    sinkClosePromise.then(_ => {+        writableStreamFinishInFlightClose(stream);+    }, error => {+        writableStreamFinishInFlightCloseWithError(stream, error);+    });+}+function writableStreamDefaultControllerProcessWrite(controller, chunk) {+    const stream = controller[controlledWritableStream_];+    writableStreamMarkFirstWriteRequestInFlight(stream);+    controller[writeAlgorithm_](chunk).then(_ => {+        writableStreamFinishInFlightWrite(stream);+        const state = stream[state_];+        dequeueValue(controller);+        if (!writableStreamCloseQueuedOrInFlight(stream) && state === "writable") {+            const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+            writableStreamUpdateBackpressure(stream, backpressure);+        }+        writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+    }, error => {+        if (stream[state_] === "writable") {+            writableStreamDefaultControllerClearAlgorithms(controller);+        }+        writableStreamFinishInFlightWriteWithError(stream, error);+    });+}+function writableStreamDefaultControllerGetBackpressure(controller) {+    const desiredSize = writableStreamDefaultControllerGetDesiredSize(controller);+    return desiredSize <= 0;+}+function writableStreamDefaultControllerError(controller, error) {+    const stream = controller[controlledWritableStream_];+    writableStreamDefaultControllerClearAlgorithms(controller);+    writableStreamStartErroring(stream, error);+}++class ReadableStreamDefaultReader {+    constructor(stream) {+        if (!isReadableStream(stream)) {+            throw new TypeError();+        }+        if (isReadableStreamLocked(stream)) {+            throw new TypeError("The stream is locked.");+        }+        readableStreamReaderGenericInitialize(this, stream);+        this[readRequests_] = [];+    }+    get closed() {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        return this[closedPromise_].promise;+    }+    cancel(reason) {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        const stream = this[ownerReadableStream_];+        if (stream === undefined) {+            return Promise.reject(new TypeError("Reader is not associated with a stream"));+        }+        return readableStreamCancel(stream, reason);+    }+    read() {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerReadableStream_] === undefined) {+            return Promise.reject(new TypeError("Reader is not associated with a stream"));+        }+        return readableStreamDefaultReaderRead(this, true);+    }+    releaseLock() {+        if (!isReadableStreamDefaultReader(this)) {+            throw new TypeError();+        }+        if (this[ownerReadableStream_] === undefined) {+            return;+        }+        if (this[readRequests_].length !== 0) {+            throw new TypeError("Cannot release a stream with pending read requests");+        }+        readableStreamReaderGenericRelease(this);+    }+}++class WritableStreamDefaultWriter {+    constructor(stream) {+        if (!isWritableStream(stream)) {+            throw new TypeError();+        }+        if (isWritableStreamLocked(stream)) {+            throw new TypeError("Stream is already locked");+        }+        this[ownerWritableStream_] = stream;+        stream[writer_] = this;+        const readyPromise = createControlledPromise();+        const closedPromise = createControlledPromise();+        this[readyPromise_] = readyPromise;+        this[closedPromise_$1] = closedPromise;+        const state = stream[state_];+        if (state === "writable") {+            if (!writableStreamCloseQueuedOrInFlight(stream) && stream[backpressure_]) ;+            else {+                readyPromise.resolve(undefined);+            }+        }+        else if (state === "erroring") {+            readyPromise.reject(stream[storedError_]);+            readyPromise.promise.catch(() => { });+        }+        else if (state === "closed") {+            readyPromise.resolve(undefined);+            closedPromise.resolve(undefined);+        }+        else {+            const storedError = stream[storedError_];+            readyPromise.reject(storedError);+            readyPromise.promise.catch(() => { });+            closedPromise.reject(storedError);+            closedPromise.promise.catch(() => { });+        }+    }+    abort(reason) {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerWritableStream_] === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        return writableStreamDefaultWriterAbort(this, reason);+    }+    close() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        const stream = this[ownerWritableStream_];+        if (stream === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        if (writableStreamCloseQueuedOrInFlight(stream)) {+            return Promise.reject(new TypeError());+        }+        return writableStreamDefaultWriterClose(this);+    }+    releaseLock() {+        const stream = this[ownerWritableStream_];+        if (stream === undefined) {+            return;+        }+        writableStreamDefaultWriterRelease(this);+    }+    write(chunk) {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerWritableStream_] === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        return writableStreamDefaultWriterWrite(this, chunk);+    }+    get closed() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        return this[closedPromise_$1].promise;+    }+    get desiredSize() {+        if (!isWritableStreamDefaultWriter(this)) {+            throw new TypeError();+        }+        if (this[ownerWritableStream_] === undefined) {+            throw new TypeError("Writer is not connected to stream");+        }+        return writableStreamDefaultWriterGetDesiredSize(this);+    }+    get ready() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        return this[readyPromise_].promise;+    }+}++function pipeTo(source, dest, options) {+    const preventClose = !!options.preventClose;+    const preventAbort = !!options.preventAbort;+    const preventCancel = !!options.preventCancel;+    const signal = options.signal;+    let shuttingDown = false;+    let latestWrite = Promise.resolve();+    const promise = createControlledPromise();+    const reader = new ReadableStreamDefaultReader(source);+    const writer = new WritableStreamDefaultWriter(dest);+    let abortAlgorithm;+    if (signal !== undefined) {+        abortAlgorithm = () => {+            const error = new DOMException("Aborted", "AbortError");+            const actions = [];+            if (preventAbort === false) {+                actions.push(() => {+                    if (dest[state_] === "writable") {+                        return writableStreamAbort(dest, error);+                    }+                    return Promise.resolve();+                });+            }+            if (preventCancel === false) {+                actions.push(() => {+                    if (source[state_] === "readable") {+                        return readableStreamCancel(source, error);+                    }+                    return Promise.resolve();+                });+            }+            shutDown(() => {+                return Promise.all(actions.map(a => a())).then(_ => undefined);+            }, { actualError: error });+        };+        if (signal.aborted === true) {+            abortAlgorithm();+        }+        else {+            signal.addEventListener("abort", abortAlgorithm);+        }+    }+    function onStreamErrored(stream, promise, action) {+        if (stream[state_] === "errored") {+            action(stream[storedError_]);+        }+        else {+            promise.catch(action);+        }+    }+    function onStreamClosed(stream, promise, action) {+        if (stream[state_] === "closed") {+            action();+        }+        else {+            promise.then(action);+        }+    }+    onStreamErrored(source, reader[closedPromise_].promise, error => {+        if (!preventAbort) {+            shutDown(() => writableStreamAbort(dest, error), { actualError: error });+        }+        else {+            shutDown(undefined, { actualError: error });+        }+    });+    onStreamErrored(dest, writer[closedPromise_$1].promise, error => {+        if (!preventCancel) {+            shutDown(() => readableStreamCancel(source, error), { actualError: error });+        }+        else {+            shutDown(undefined, { actualError: error });+        }+    });+    onStreamClosed(source, reader[closedPromise_].promise, () => {+        if (!preventClose) {+            shutDown(() => writableStreamDefaultWriterCloseWithErrorPropagation(writer));+        }+        else {+            shutDown();+        }+    });+    if (writableStreamCloseQueuedOrInFlight(dest) || dest[state_] === "closed") {+        const destClosed = new TypeError();+        if (!preventCancel) {+            shutDown(() => readableStreamCancel(source, destClosed), { actualError: destClosed });+        }+        else {+            shutDown(undefined, { actualError: destClosed });+        }+    }+    function awaitLatestWrite() {+        const curLatestWrite = latestWrite;+        return latestWrite.then(() => curLatestWrite === latestWrite ? undefined : awaitLatestWrite());+    }+    function flushRemainder() {+        if (dest[state_] === "writable" && (!writableStreamCloseQueuedOrInFlight(dest))) {+            return awaitLatestWrite();+        }+        else {+            return undefined;+        }+    }+    function shutDown(action, error) {+        if (shuttingDown) {+            return;+        }+        shuttingDown = true;+        if (action === undefined) {+            action = () => Promise.resolve();+        }+        function finishShutDown() {+            action().then(_ => finalize(error), newError => finalize({ actualError: newError }));+        }+        const flushWait = flushRemainder();+        if (flushWait) {+            flushWait.then(finishShutDown);+        }+        else {+            finishShutDown();+        }+    }+    function finalize(error) {+        writableStreamDefaultWriterRelease(writer);+        readableStreamReaderGenericRelease(reader);+        if (signal && abortAlgorithm) {+            signal.removeEventListener("abort", abortAlgorithm);+        }+        if (error) {+            promise.reject(error.actualError);+        }+        else {+            promise.resolve(undefined);+        }+    }+    function next() {+        if (shuttingDown) {+            return;+        }+        writer[readyPromise_].promise.then(() => {+            readableStreamDefaultReaderRead(reader).then(({ value, done }) => {+                if (done) {+                    return;+                }+                latestWrite = writableStreamDefaultWriterWrite(writer, value).catch(() => { });+                next();+            }, _error => {+                latestWrite = Promise.resolve();+            });+        });+    }+    if (!shuttingDown) {+        next();+    }+    return promise.promise;+}++class ReadableStreamDefaultController {+    constructor() {+        throw new TypeError();+    }+    get desiredSize() {+        ret

I don't completely understand how /third_party works, but would it make more sense to include this there?

mrkurt

comment created time in 20 days

Pull request review commentdenoland/deno

Global request response

+/**+* @stardazed/streams - implementation of the web streams standard+* Part of Stardazed+* (c) 2018-Present by Arthur Langereis - @zenmumbler+* https://github.com/stardazed/sd-streams+*/++const state_ = Symbol("state_");+const storedError_ = Symbol("storedError_");+function isInteger(value) {+    if (!isFinite(value)) {+        return false;+    }+    const absValue = Math.abs(value);+    return Math.floor(absValue) === absValue;+}+function isFiniteNonNegativeNumber(value) {+    if (!(typeof value === "number" && isFinite(value))) {+        return false;+    }+    return value >= 0;+}+function isAbortSignal(signal) {+    if (typeof signal !== "object" || signal === null) {+        return false;+    }+    try {+        const aborted = Object.getOwnPropertyDescriptor(AbortSignal.prototype, "aborted").get;+        aborted.call(signal);+        return true;+    }+    catch (err) {+        return false;+    }+}+function invokeOrNoop(o, p, args) {+    const method = o[p];+    if (method === undefined) {+        return undefined;+    }+    return Function.prototype.apply.call(method, o, args);+}+function cloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, cloneConstructor) {+    return srcBuffer.slice(srcByteOffset, srcByteOffset + srcLength);+}+function transferArrayBuffer(buffer) {+    return buffer.slice(0);+}+function copyDataBlockBytes(toBlock, toIndex, fromBlock, fromIndex, count) {+    new Uint8Array(toBlock, toIndex, count).set(new Uint8Array(fromBlock, fromIndex, count));+}+const objectCloneMemo = new WeakMap();+let sharedArrayBufferSupported_;+function supportsSharedArrayBuffer() {+    if (sharedArrayBufferSupported_ === undefined) {+        try {+            new SharedArrayBuffer(16);+            sharedArrayBufferSupported_ = true;+        }+        catch (e) {+            sharedArrayBufferSupported_ = false;+        }+    }+    return sharedArrayBufferSupported_;+}+function cloneValue(value) {+    const valueType = typeof value;+    switch (valueType) {+        case "number":+        case "string":+        case "boolean":+        case "undefined":+        case "bigint":+            return value;+        case "object": {+            if (objectCloneMemo.has(value)) {+                return objectCloneMemo.get(value);+            }+            if (value === null) {+                return value;+            }+            if (value instanceof Date) {+                return new Date(value.valueOf());+            }+            if (value instanceof RegExp) {+                return new RegExp(value);+            }+            if (supportsSharedArrayBuffer() && value instanceof SharedArrayBuffer) {+                return value;+            }+            if (value instanceof ArrayBuffer) {+                const cloned = cloneArrayBuffer(value, 0, value.byteLength, ArrayBuffer);+                objectCloneMemo.set(value, cloned);+                return cloned;+            }+            if (ArrayBuffer.isView(value)) {+                const clonedBuffer = cloneValue(value.buffer);+                let length;+                if (value instanceof DataView) {+                    length = value.byteLength;+                }+                else {+                    length = value.length;+                }+                return new value.constructor(clonedBuffer, value.byteOffset, length);+            }+            if (value instanceof Map) {+                const clonedMap = new Map();+                objectCloneMemo.set(value, clonedMap);+                value.forEach((v, k) => clonedMap.set(k, cloneValue(v)));+                return clonedMap;+            }+            if (value instanceof Set) {+                const clonedSet = new Map();+                objectCloneMemo.set(value, clonedSet);+                value.forEach((v, k) => clonedSet.set(k, cloneValue(v)));+                return clonedSet;+            }+            const clonedObj = {};+            objectCloneMemo.set(value, clonedObj);+            const sourceKeys = Object.getOwnPropertyNames(value);+            for (const key of sourceKeys) {+                clonedObj[key] = cloneValue(value[key]);+            }+            return clonedObj;+        }+        case "symbol":+        case "function":+        default:+            throw new DOMException("Uncloneable value in stream", "DataCloneError");+    }+}+function promiseCall(f, v, args) {+    try {+        const result = Function.prototype.apply.call(f, v, args);+        return Promise.resolve(result);+    }+    catch (err) {+        return Promise.reject(err);+    }+}+function createAlgorithmFromUnderlyingMethod(obj, methodName, extraArgs) {+    const method = obj[methodName];+    if (method === undefined) {+        return () => Promise.resolve(undefined);+    }+    if (typeof method !== "function") {+        throw new TypeError(`Field "${methodName}" is not a function.`);+    }+    return function (...fnArgs) {+        return promiseCall(method, obj, fnArgs.concat(extraArgs));+    };+}+function validateAndNormalizeHighWaterMark(hwm) {+    const highWaterMark = Number(hwm);+    if (isNaN(highWaterMark) || highWaterMark < 0) {+        throw new RangeError("highWaterMark must be a valid, non-negative integer.");+    }+    return highWaterMark;+}+function makeSizeAlgorithmFromSizeFunction(sizeFn) {+    if (typeof sizeFn !== "function" && typeof sizeFn !== "undefined") {+        throw new TypeError("size function must be undefined or a function");+    }+    return function (chunk) {+        if (typeof sizeFn === "function") {+            return sizeFn(chunk);+        }+        return 1;+    };+}+var ControlledPromiseState;+(function (ControlledPromiseState) {+    ControlledPromiseState[ControlledPromiseState["Pending"] = 0] = "Pending";+    ControlledPromiseState[ControlledPromiseState["Resolved"] = 1] = "Resolved";+    ControlledPromiseState[ControlledPromiseState["Rejected"] = 2] = "Rejected";+})(ControlledPromiseState || (ControlledPromiseState = {}));+function createControlledPromise() {+    const conProm = {+        state: ControlledPromiseState.Pending+    };+    conProm.promise = new Promise(function (resolve, reject) {+        conProm.resolve = function (v) { conProm.state = ControlledPromiseState.Resolved; resolve(v); };+        conProm.reject = function (e) { conProm.state = ControlledPromiseState.Rejected; reject(e); };+    });+    return conProm;+}++const CHUNK_SIZE = 16384;+class QueueImpl {+    constructor() {+        this.chunks_ = [[]];+        this.readChunk_ = this.writeChunk_ = this.chunks_[0];+        this.length_ = 0;+    }+    push(t) {+        this.writeChunk_.push(t);+        this.length_ += 1;+        if (this.writeChunk_.length === CHUNK_SIZE) {+            this.writeChunk_ = [];+            this.chunks_.push(this.writeChunk_);+        }+    }+    front() {+        if (this.length_ === 0) {+            return undefined;+        }+        return this.readChunk_[0];+    }+    shift() {+        if (this.length_ === 0) {+            return undefined;+        }+        const t = this.readChunk_.shift();+        this.length_ -= 1;+        if (this.readChunk_.length === 0 && this.readChunk_ !== this.writeChunk_) {+            this.chunks_.shift();+            this.readChunk_ = this.chunks_[0];+        }+        return t;+    }+    get length() {+        return this.length_;+    }+}++const queue_ = Symbol("queue_");+const queueTotalSize_ = Symbol("queueTotalSize_");+function dequeueValue(container) {+    const pair = container[queue_].shift();+    const newTotalSize = container[queueTotalSize_] - pair.size;+    container[queueTotalSize_] = Math.max(0, newTotalSize);+    return pair.value;+}+function enqueueValueWithSize(container, value, size) {+    if (!isFiniteNonNegativeNumber(size)) {+        throw new RangeError("Chunk size must be a non-negative, finite numbers");+    }+    container[queue_].push({ value, size });+    container[queueTotalSize_] += size;+}+function peekQueueValue(container) {+    return container[queue_].front().value;+}+function resetQueue(container) {+    container[queue_] = new QueueImpl();+    container[queueTotalSize_] = 0;+}++const controlledReadableStream_ = Symbol("controlledReadableStream_");+const pullAlgorithm_ = Symbol("pullAlgorithm_");+const cancelAlgorithm_ = Symbol("cancelAlgorithm_");+const strategySizeAlgorithm_ = Symbol("strategySizeAlgorithm_");+const strategyHWM_ = Symbol("strategyHWM_");+const started_ = Symbol("started_");+const closeRequested_ = Symbol("closeRequested_");+const pullAgain_ = Symbol("pullAgain_");+const pulling_ = Symbol("pulling_");+const cancelSteps_ = Symbol("cancelSteps_");+const pullSteps_ = Symbol("pullSteps_");+const autoAllocateChunkSize_ = Symbol("autoAllocateChunkSize_");+const byobRequest_ = Symbol("byobRequest_");+const controlledReadableByteStream_ = Symbol("controlledReadableByteStream_");+const pendingPullIntos_ = Symbol("pendingPullIntos_");+const closedPromise_ = Symbol("closedPromise_");+const ownerReadableStream_ = Symbol("ownerReadableStream_");+const readRequests_ = Symbol("readRequests_");+const readIntoRequests_ = Symbol("readIntoRequests_");+const associatedReadableByteStreamController_ = Symbol("associatedReadableByteStreamController_");+const view_ = Symbol("view_");+const reader_ = Symbol("reader_");+const readableStreamController_ = Symbol("readableStreamController_");+function initializeReadableStream(stream) {+    stream[state_] = "readable";+    stream[reader_] = undefined;+    stream[storedError_] = undefined;+    stream[readableStreamController_] = undefined;+}+function isReadableStream(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return readableStreamController_ in value;+}+function isReadableStreamLocked(stream) {+    return stream[reader_] !== undefined;+}+function readableStreamGetNumReadIntoRequests(stream) {+    const reader = stream[reader_];+    if (reader === undefined) {+        return 0;+    }+    return reader[readIntoRequests_].length;+}+function readableStreamGetNumReadRequests(stream) {+    const reader = stream[reader_];+    if (reader === undefined) {+        return 0;+    }+    return reader[readRequests_].length;+}+function readableStreamCreateReadResult(value, done, forAuthorCode) {+    const prototype = forAuthorCode ? Object.prototype : null;+    const result = Object.create(prototype);+    result.value = value;+    result.done = done;+    return result;+}+function readableStreamAddReadIntoRequest(stream, forAuthorCode) {+    const reader = stream[reader_];+    const conProm = createControlledPromise();+    conProm.forAuthorCode = forAuthorCode;+    reader[readIntoRequests_].push(conProm);+    return conProm.promise;+}+function readableStreamAddReadRequest(stream, forAuthorCode) {+    const reader = stream[reader_];+    const conProm = createControlledPromise();+    conProm.forAuthorCode = forAuthorCode;+    reader[readRequests_].push(conProm);+    return conProm.promise;+}+function readableStreamHasBYOBReader(stream) {+    const reader = stream[reader_];+    return isReadableStreamBYOBReader(reader);+}+function readableStreamHasDefaultReader(stream) {+    const reader = stream[reader_];+    return isReadableStreamDefaultReader(reader);+}+function readableStreamCancel(stream, reason) {+    if (stream[state_] === "closed") {+        return Promise.resolve(undefined);+    }+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    readableStreamClose(stream);+    const sourceCancelPromise = stream[readableStreamController_][cancelSteps_](reason);+    return sourceCancelPromise.then(_ => undefined);+}+function readableStreamClose(stream) {+    stream[state_] = "closed";+    const reader = stream[reader_];+    if (reader === undefined) {+        return;+    }+    if (isReadableStreamDefaultReader(reader)) {+        for (const readRequest of reader[readRequests_]) {+            readRequest.resolve(readableStreamCreateReadResult(undefined, true, readRequest.forAuthorCode));+        }+        reader[readRequests_] = [];+    }+    reader[closedPromise_].resolve();+    reader[closedPromise_].promise.catch(() => { });+}+function readableStreamError(stream, error) {+    if (stream[state_] !== "readable") {+        throw new RangeError("Stream is in an invalid state");+    }+    stream[state_] = "errored";+    stream[storedError_] = error;+    const reader = stream[reader_];+    if (reader === undefined) {+        return;+    }+    if (isReadableStreamDefaultReader(reader)) {+        for (const readRequest of reader[readRequests_]) {+            readRequest.reject(error);+        }+        reader[readRequests_] = [];+    }+    else {+        const readIntoRequests = reader[readIntoRequests_];+        for (const readIntoRequest of readIntoRequests) {+            readIntoRequest.reject(error);+        }+        reader[readIntoRequests_] = [];+    }+    reader[closedPromise_].reject(error);+}+function isReadableStreamDefaultReader(reader) {+    if (typeof reader !== "object" || reader === null) {+        return false;+    }+    return readRequests_ in reader;+}+function isReadableStreamBYOBReader(reader) {+    if (typeof reader !== "object" || reader === null) {+        return false;+    }+    return readIntoRequests_ in reader;+}+function readableStreamReaderGenericInitialize(reader, stream) {+    reader[ownerReadableStream_] = stream;+    stream[reader_] = reader;+    const streamState = stream[state_];+    reader[closedPromise_] = createControlledPromise();+    if (streamState === "readable") ;+    else if (streamState === "closed") {+        reader[closedPromise_].resolve(undefined);+    }+    else {+        reader[closedPromise_].reject(stream[storedError_]);+        reader[closedPromise_].promise.catch(() => { });+    }+}+function readableStreamReaderGenericRelease(reader) {+    const stream = reader[ownerReadableStream_];+    if (stream === undefined) {+        throw new TypeError("Reader is in an inconsistent state");+    }+    if (stream[state_] === "readable") ;+    else {+        reader[closedPromise_] = createControlledPromise();+    }+    reader[closedPromise_].reject(new TypeError());+    reader[closedPromise_].promise.catch(() => { });+    stream[reader_] = undefined;+    reader[ownerReadableStream_] = undefined;+}+function readableStreamBYOBReaderRead(reader, view, forAuthorCode = false) {+    const stream = reader[ownerReadableStream_];+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return readableByteStreamControllerPullInto(stream[readableStreamController_], view, forAuthorCode);+}+function readableStreamDefaultReaderRead(reader, forAuthorCode = false) {+    const stream = reader[ownerReadableStream_];+    if (stream[state_] === "closed") {+        return Promise.resolve(readableStreamCreateReadResult(undefined, true, forAuthorCode));+    }+    if (stream[state_] === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return stream[readableStreamController_][pullSteps_](forAuthorCode);+}+function readableStreamFulfillReadIntoRequest(stream, chunk, done) {+    const reader = stream[reader_];+    const readIntoRequest = reader[readIntoRequests_].shift();+    readIntoRequest.resolve(readableStreamCreateReadResult(chunk, done, readIntoRequest.forAuthorCode));+}+function readableStreamFulfillReadRequest(stream, chunk, done) {+    const reader = stream[reader_];+    const readRequest = reader[readRequests_].shift();+    readRequest.resolve(readableStreamCreateReadResult(chunk, done, readRequest.forAuthorCode));+}+function setUpReadableStreamDefaultController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, sizeAlgorithm) {+    controller[controlledReadableStream_] = stream;+    resetQueue(controller);+    controller[started_] = false;+    controller[closeRequested_] = false;+    controller[pullAgain_] = false;+    controller[pulling_] = false;+    controller[strategySizeAlgorithm_] = sizeAlgorithm;+    controller[strategyHWM_] = highWaterMark;+    controller[pullAlgorithm_] = pullAlgorithm;+    controller[cancelAlgorithm_] = cancelAlgorithm;+    stream[readableStreamController_] = controller;+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_] = true;+        readableStreamDefaultControllerCallPullIfNeeded(controller);+    }, error => {+        readableStreamDefaultControllerError(controller, error);+    });+}+function isReadableStreamDefaultController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledReadableStream_ in value;+}+function readableStreamDefaultControllerHasBackpressure(controller) {+    return !readableStreamDefaultControllerShouldCallPull(controller);+}+function readableStreamDefaultControllerCanCloseOrEnqueue(controller) {+    const state = controller[controlledReadableStream_][state_];+    return controller[closeRequested_] === false && state === "readable";+}+function readableStreamDefaultControllerGetDesiredSize(controller) {+    const state = controller[controlledReadableStream_][state_];+    if (state === "errored") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return controller[strategyHWM_] - controller[queueTotalSize_];+}+function readableStreamDefaultControllerClose(controller) {+    controller[closeRequested_] = true;+    const stream = controller[controlledReadableStream_];+    if (controller[queue_].length === 0) {+        readableStreamDefaultControllerClearAlgorithms(controller);+        readableStreamClose(stream);+    }+}+function readableStreamDefaultControllerEnqueue(controller, chunk) {+    const stream = controller[controlledReadableStream_];+    if (isReadableStreamLocked(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        readableStreamFulfillReadRequest(stream, chunk, false);+    }+    else {+        let chunkSize;+        try {+            chunkSize = controller[strategySizeAlgorithm_](chunk);+        }+        catch (error) {+            readableStreamDefaultControllerError(controller, error);+            throw error;+        }+        try {+            enqueueValueWithSize(controller, chunk, chunkSize);+        }+        catch (error) {+            readableStreamDefaultControllerError(controller, error);+            throw error;+        }+    }+    readableStreamDefaultControllerCallPullIfNeeded(controller);+}+function readableStreamDefaultControllerError(controller, error) {+    const stream = controller[controlledReadableStream_];+    if (stream[state_] !== "readable") {+        return;+    }+    resetQueue(controller);+    readableStreamDefaultControllerClearAlgorithms(controller);+    readableStreamError(stream, error);+}+function readableStreamDefaultControllerCallPullIfNeeded(controller) {+    if (!readableStreamDefaultControllerShouldCallPull(controller)) {+        return;+    }+    if (controller[pulling_]) {+        controller[pullAgain_] = true;+        return;+    }+    if (controller[pullAgain_]) {+        throw new RangeError("Stream controller is in an invalid state.");+    }+    controller[pulling_] = true;+    controller[pullAlgorithm_](controller).then(_ => {+        controller[pulling_] = false;+        if (controller[pullAgain_]) {+            controller[pullAgain_] = false;+            readableStreamDefaultControllerCallPullIfNeeded(controller);+        }+    }, error => {+        readableStreamDefaultControllerError(controller, error);+    });+}+function readableStreamDefaultControllerShouldCallPull(controller) {+    const stream = controller[controlledReadableStream_];+    if (!readableStreamDefaultControllerCanCloseOrEnqueue(controller)) {+        return false;+    }+    if (controller[started_] === false) {+        return false;+    }+    if (isReadableStreamLocked(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        return true;+    }+    const desiredSize = readableStreamDefaultControllerGetDesiredSize(controller);+    if (desiredSize === null) {+        throw new RangeError("Stream is in an invalid state.");+    }+    return desiredSize > 0;+}+function readableStreamDefaultControllerClearAlgorithms(controller) {+    controller[pullAlgorithm_] = undefined;+    controller[cancelAlgorithm_] = undefined;+    controller[strategySizeAlgorithm_] = undefined;+}+function setUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, highWaterMark, autoAllocateChunkSize) {+    if (stream[readableStreamController_] !== undefined) {+        throw new TypeError("Cannot reuse streams");+    }+    if (autoAllocateChunkSize !== undefined) {+        if (!isInteger(autoAllocateChunkSize) || autoAllocateChunkSize <= 0) {+            throw new RangeError("autoAllocateChunkSize must be a positive, finite integer");+        }+    }+    controller[controlledReadableByteStream_] = stream;+    controller[pullAgain_] = false;+    controller[pulling_] = false;+    readableByteStreamControllerClearPendingPullIntos(controller);+    resetQueue(controller);+    controller[closeRequested_] = false;+    controller[started_] = false;+    controller[strategyHWM_] = validateAndNormalizeHighWaterMark(highWaterMark);+    controller[pullAlgorithm_] = pullAlgorithm;+    controller[cancelAlgorithm_] = cancelAlgorithm;+    controller[autoAllocateChunkSize_] = autoAllocateChunkSize;+    controller[pendingPullIntos_] = [];+    stream[readableStreamController_] = controller;+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_] = true;+        readableByteStreamControllerCallPullIfNeeded(controller);+    }, error => {+        readableByteStreamControllerError(controller, error);+    });+}+function isReadableStreamBYOBRequest(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return associatedReadableByteStreamController_ in value;+}+function isReadableByteStreamController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledReadableByteStream_ in value;+}+function readableByteStreamControllerCallPullIfNeeded(controller) {+    if (!readableByteStreamControllerShouldCallPull(controller)) {+        return;+    }+    if (controller[pulling_]) {+        controller[pullAgain_] = true;+        return;+    }+    controller[pulling_] = true;+    controller[pullAlgorithm_](controller).then(_ => {+        controller[pulling_] = false;+        if (controller[pullAgain_]) {+            controller[pullAgain_] = false;+            readableByteStreamControllerCallPullIfNeeded(controller);+        }+    }, error => {+        readableByteStreamControllerError(controller, error);+    });+}+function readableByteStreamControllerClearAlgorithms(controller) {+    controller[pullAlgorithm_] = undefined;+    controller[cancelAlgorithm_] = undefined;+}+function readableByteStreamControllerClearPendingPullIntos(controller) {+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    controller[pendingPullIntos_] = [];+}+function readableByteStreamControllerClose(controller) {+    const stream = controller[controlledReadableByteStream_];+    if (controller[queueTotalSize_] > 0) {+        controller[closeRequested_] = true;+        return;+    }+    if (controller[pendingPullIntos_].length > 0) {+        const firstPendingPullInto = controller[pendingPullIntos_][0];+        if (firstPendingPullInto.bytesFilled > 0) {+            const error = new TypeError();+            readableByteStreamControllerError(controller, error);+            throw error;+        }+    }+    readableByteStreamControllerClearAlgorithms(controller);+    readableStreamClose(stream);+}+function readableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) {+    let done = false;+    if (stream[state_] === "closed") {+        done = true;+    }+    const filledView = readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);+    if (pullIntoDescriptor.readerType === "default") {+        readableStreamFulfillReadRequest(stream, filledView, done);+    }+    else {+        readableStreamFulfillReadIntoRequest(stream, filledView, done);+    }+}+function readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) {+    const { bytesFilled, elementSize } = pullIntoDescriptor;+    return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize);+}+function readableByteStreamControllerEnqueue(controller, chunk) {+    const stream = controller[controlledReadableByteStream_];+    const { buffer, byteOffset, byteLength } = chunk;+    const transferredBuffer = transferArrayBuffer(buffer);+    if (readableStreamHasDefaultReader(stream)) {+        if (readableStreamGetNumReadRequests(stream) === 0) {+            readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+        }+        else {+            const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);+            readableStreamFulfillReadRequest(stream, transferredView, false);+        }+    }+    else if (readableStreamHasBYOBReader(stream)) {+        readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+        readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);+    }+    else {+        readableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);+    }+    readableByteStreamControllerCallPullIfNeeded(controller);+}+function readableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) {+    controller[queue_].push({ buffer, byteOffset, byteLength });+    controller[queueTotalSize_] += byteLength;+}+function readableByteStreamControllerError(controller, error) {+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] !== "readable") {+        return;+    }+    readableByteStreamControllerClearPendingPullIntos(controller);+    resetQueue(controller);+    readableByteStreamControllerClearAlgorithms(controller);+    readableStreamError(stream, error);+}+function readableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) {+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    pullIntoDescriptor.bytesFilled += size;+}+function readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) {+    const elementSize = pullIntoDescriptor.elementSize;+    const currentAlignedBytes = pullIntoDescriptor.bytesFilled - (pullIntoDescriptor.bytesFilled % elementSize);+    const maxBytesToCopy = Math.min(controller[queueTotalSize_], pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled);+    const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;+    const maxAlignedBytes = maxBytesFilled - (maxBytesFilled % elementSize);+    let totalBytesToCopyRemaining = maxBytesToCopy;+    let ready = false;+    if (maxAlignedBytes > currentAlignedBytes) {+        totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;+        ready = true;+    }+    const queue = controller[queue_];+    while (totalBytesToCopyRemaining > 0) {+        const headOfQueue = queue.front();+        const bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength);+        const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;+        copyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy);+        if (headOfQueue.byteLength === bytesToCopy) {+            queue.shift();+        }+        else {+            headOfQueue.byteOffset += bytesToCopy;+            headOfQueue.byteLength -= bytesToCopy;+        }+        controller[queueTotalSize_] -= bytesToCopy;+        readableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor);+        totalBytesToCopyRemaining -= bytesToCopy;+    }+    return ready;+}+function readableByteStreamControllerGetDesiredSize(controller) {+    const stream = controller[controlledReadableByteStream_];+    const state = stream[state_];+    if (state === "errored") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return controller[strategyHWM_] - controller[queueTotalSize_];+}+function readableByteStreamControllerHandleQueueDrain(controller) {+    if (controller[queueTotalSize_] === 0 && controller[closeRequested_]) {+        readableByteStreamControllerClearAlgorithms(controller);+        readableStreamClose(controller[controlledReadableByteStream_]);+    }+    else {+        readableByteStreamControllerCallPullIfNeeded(controller);+    }+}+function readableByteStreamControllerInvalidateBYOBRequest(controller) {+    const byobRequest = controller[byobRequest_];+    if (byobRequest === undefined) {+        return;+    }+    byobRequest[associatedReadableByteStreamController_] = undefined;+    byobRequest[view_] = undefined;+    controller[byobRequest_] = undefined;+}+function readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) {+    const pendingPullIntos = controller[pendingPullIntos_];+    while (pendingPullIntos.length > 0) {+        if (controller[queueTotalSize_] === 0) {+            return;+        }+        const pullIntoDescriptor = pendingPullIntos[0];+        if (readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {+            readableByteStreamControllerShiftPendingPullInto(controller);+            readableByteStreamControllerCommitPullIntoDescriptor(controller[controlledReadableByteStream_], pullIntoDescriptor);+        }+    }+}+function readableByteStreamControllerPullInto(controller, view, forAuthorCode) {+    const stream = controller[controlledReadableByteStream_];+    const elementSize = view.BYTES_PER_ELEMENT || 1;+    const ctor = view.constructor;+    const byteOffset = view.byteOffset;+    const byteLength = view.byteLength;+    const buffer = transferArrayBuffer(view.buffer);+    const pullIntoDescriptor = { buffer, byteOffset, byteLength, bytesFilled: 0, elementSize, ctor, readerType: "byob" };+    if (controller[pendingPullIntos_].length > 0) {+        controller[pendingPullIntos_].push(pullIntoDescriptor);+        return readableStreamAddReadIntoRequest(stream, forAuthorCode);+    }+    if (stream[state_] === "closed") {+        const emptyView = new ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0);+        return Promise.resolve(readableStreamCreateReadResult(emptyView, true, forAuthorCode));+    }+    if (controller[queueTotalSize_] > 0) {+        if (readableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor)) {+            const filledView = readableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor);+            readableByteStreamControllerHandleQueueDrain(controller);+            return Promise.resolve(readableStreamCreateReadResult(filledView, false, forAuthorCode));+        }+        if (controller[closeRequested_]) {+            const error = new TypeError();+            readableByteStreamControllerError(controller, error);+            return Promise.reject(error);+        }+    }+    controller[pendingPullIntos_].push(pullIntoDescriptor);+    const promise = readableStreamAddReadIntoRequest(stream, forAuthorCode);+    readableByteStreamControllerCallPullIfNeeded(controller);+    return promise;+}+function readableByteStreamControllerRespond(controller, bytesWritten) {+    bytesWritten = Number(bytesWritten);+    if (!isFiniteNonNegativeNumber(bytesWritten)) {+        throw new RangeError("bytesWritten must be a finite, non-negative number");+    }+    readableByteStreamControllerRespondInternal(controller, bytesWritten);+}+function readableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {+    firstDescriptor.buffer = transferArrayBuffer(firstDescriptor.buffer);+    const stream = controller[controlledReadableByteStream_];+    if (readableStreamHasBYOBReader(stream)) {+        while (readableStreamGetNumReadIntoRequests(stream) > 0) {+            const pullIntoDescriptor = readableByteStreamControllerShiftPendingPullInto(controller);+            readableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor);+        }+    }+}+function readableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) {+    if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) {+        throw new RangeError();+    }+    readableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor);+    if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) {+        return;+    }+    readableByteStreamControllerShiftPendingPullInto(controller);+    const remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize;+    if (remainderSize > 0) {+        const end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled;+        const remainder = cloneArrayBuffer(pullIntoDescriptor.buffer, end - remainderSize, remainderSize, ArrayBuffer);+        readableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength);+    }+    pullIntoDescriptor.buffer = transferArrayBuffer(pullIntoDescriptor.buffer);+    pullIntoDescriptor.bytesFilled = pullIntoDescriptor.bytesFilled - remainderSize;+    readableByteStreamControllerCommitPullIntoDescriptor(controller[controlledReadableByteStream_], pullIntoDescriptor);+    readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller);+}+function readableByteStreamControllerRespondInternal(controller, bytesWritten) {+    const firstDescriptor = controller[pendingPullIntos_][0];+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] === "closed") {+        if (bytesWritten !== 0) {+            throw new TypeError();+        }+        readableByteStreamControllerRespondInClosedState(controller, firstDescriptor);+    }+    else {+        readableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);+    }+    readableByteStreamControllerCallPullIfNeeded(controller);+}+function readableByteStreamControllerRespondWithNewView(controller, view) {+    const firstDescriptor = controller[pendingPullIntos_][0];+    if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) {+        throw new RangeError();+    }+    if (firstDescriptor.byteLength !== view.byteLength) {+        throw new RangeError();+    }+    firstDescriptor.buffer = view.buffer;+    readableByteStreamControllerRespondInternal(controller, view.byteLength);+}+function readableByteStreamControllerShiftPendingPullInto(controller) {+    const descriptor = controller[pendingPullIntos_].shift();+    readableByteStreamControllerInvalidateBYOBRequest(controller);+    return descriptor;+}+function readableByteStreamControllerShouldCallPull(controller) {+    const stream = controller[controlledReadableByteStream_];+    if (stream[state_] !== "readable") {+        return false;+    }+    if (controller[closeRequested_]) {+        return false;+    }+    if (!controller[started_]) {+        return false;+    }+    if (readableStreamHasDefaultReader(stream) && readableStreamGetNumReadRequests(stream) > 0) {+        return true;+    }+    if (readableStreamHasBYOBReader(stream) && readableStreamGetNumReadIntoRequests(stream) > 0) {+        return true;+    }+    const desiredSize = readableByteStreamControllerGetDesiredSize(controller);+    return desiredSize > 0;+}+function setUpReadableStreamBYOBRequest(request, controller, view) {+    if (!isReadableByteStreamController(controller)) {+        throw new TypeError();+    }+    if (!ArrayBuffer.isView(view)) {+        throw new TypeError();+    }+    request[associatedReadableByteStreamController_] = controller;+    request[view_] = view;+}++const backpressure_ = Symbol("backpressure_");+const closeRequest_ = Symbol("closeRequest_");+const inFlightWriteRequest_ = Symbol("inFlightWriteRequest_");+const inFlightCloseRequest_ = Symbol("inFlightCloseRequest_");+const pendingAbortRequest_ = Symbol("pendingAbortRequest_");+const writableStreamController_ = Symbol("writableStreamController_");+const writer_ = Symbol("writer_");+const writeRequests_ = Symbol("writeRequests_");+const abortAlgorithm_ = Symbol("abortAlgorithm_");+const closeAlgorithm_ = Symbol("closeAlgorithm_");+const controlledWritableStream_ = Symbol("controlledWritableStream_");+const started_$1 = Symbol("started_");+const strategyHWM_$1 = Symbol("strategyHWM_");+const strategySizeAlgorithm_$1 = Symbol("strategySizeAlgorithm_");+const writeAlgorithm_ = Symbol("writeAlgorithm_");+const ownerWritableStream_ = Symbol("ownerWritableStream_");+const closedPromise_$1 = Symbol("closedPromise_");+const readyPromise_ = Symbol("readyPromise_");+const errorSteps_ = Symbol("errorSteps_");+const abortSteps_ = Symbol("abortSteps_");+function initializeWritableStream(stream) {+    stream[state_] = "writable";+    stream[storedError_] = undefined;+    stream[writer_] = undefined;+    stream[writableStreamController_] = undefined;+    stream[inFlightWriteRequest_] = undefined;+    stream[closeRequest_] = undefined;+    stream[inFlightCloseRequest_] = undefined;+    stream[pendingAbortRequest_] = undefined;+    stream[writeRequests_] = [];+    stream[backpressure_] = false;+}+function isWritableStream(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return writableStreamController_ in value;+}+function isWritableStreamLocked(stream) {+    return stream[writer_] !== undefined;+}+function writableStreamAbort(stream, reason) {+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return Promise.resolve(undefined);+    }+    let pending = stream[pendingAbortRequest_];+    if (pending !== undefined) {+        return pending.promise;+    }+    let wasAlreadyErroring = false;+    if (state === "erroring") {+        wasAlreadyErroring = true;+        reason = undefined;+    }+    pending = {+        reason,+        wasAlreadyErroring+    };+    const promise = new Promise((resolve, reject) => {+        pending.resolve = resolve;+        pending.reject = reject;+    });+    pending.promise = promise;+    stream[pendingAbortRequest_] = pending;+    if (!wasAlreadyErroring) {+        writableStreamStartErroring(stream, reason);+    }+    return promise;+}+function writableStreamAddWriteRequest(stream) {+    const writePromise = createControlledPromise();+    stream[writeRequests_].push(writePromise);+    return writePromise.promise;+}+function writableStreamDealWithRejection(stream, error) {+    const state = stream[state_];+    if (state === "writable") {+        writableStreamStartErroring(stream, error);+        return;+    }+    writableStreamFinishErroring(stream);+}+function writableStreamStartErroring(stream, reason) {+    const controller = stream[writableStreamController_];+    stream[state_] = "erroring";+    stream[storedError_] = reason;+    const writer = stream[writer_];+    if (writer !== undefined) {+        writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason);+    }+    if (!writableStreamHasOperationMarkedInFlight(stream) && controller[started_$1]) {+        writableStreamFinishErroring(stream);+    }+}+function writableStreamFinishErroring(stream) {+    stream[state_] = "errored";+    const controller = stream[writableStreamController_];+    controller[errorSteps_]();+    const storedError = stream[storedError_];+    for (const writeRequest of stream[writeRequests_]) {+        writeRequest.reject(storedError);+    }+    stream[writeRequests_] = [];+    const abortRequest = stream[pendingAbortRequest_];+    if (abortRequest === undefined) {+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+        return;+    }+    stream[pendingAbortRequest_] = undefined;+    if (abortRequest.wasAlreadyErroring) {+        abortRequest.reject(storedError);+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+        return;+    }+    const promise = controller[abortSteps_](abortRequest.reason);+    promise.then(_ => {+        abortRequest.resolve();+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+    }, error => {+        abortRequest.reject(error);+        writableStreamRejectCloseAndClosedPromiseIfNeeded(stream);+    });+}+function writableStreamFinishInFlightWrite(stream) {+    stream[inFlightWriteRequest_].resolve(undefined);+    stream[inFlightWriteRequest_] = undefined;+}+function writableStreamFinishInFlightWriteWithError(stream, error) {+    stream[inFlightWriteRequest_].reject(error);+    stream[inFlightWriteRequest_] = undefined;+    writableStreamDealWithRejection(stream, error);+}+function writableStreamFinishInFlightClose(stream) {+    stream[inFlightCloseRequest_].resolve(undefined);+    stream[inFlightCloseRequest_] = undefined;+    const state = stream[state_];+    if (state === "erroring") {+        stream[storedError_] = undefined;+        if (stream[pendingAbortRequest_] !== undefined) {+            stream[pendingAbortRequest_].resolve();+            stream[pendingAbortRequest_] = undefined;+        }+    }+    stream[state_] = "closed";+    const writer = stream[writer_];+    if (writer !== undefined) {+        writer[closedPromise_$1].resolve(undefined);+    }+}+function writableStreamFinishInFlightCloseWithError(stream, error) {+    stream[inFlightCloseRequest_].reject(error);+    stream[inFlightCloseRequest_] = undefined;+    if (stream[pendingAbortRequest_] !== undefined) {+        stream[pendingAbortRequest_].reject(error);+        stream[pendingAbortRequest_] = undefined;+    }+    writableStreamDealWithRejection(stream, error);+}+function writableStreamCloseQueuedOrInFlight(stream) {+    return (stream[closeRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined);+}+function writableStreamHasOperationMarkedInFlight(stream) {+    return stream[inFlightWriteRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined;+}+function writableStreamMarkCloseRequestInFlight(stream) {+    stream[inFlightCloseRequest_] = stream[closeRequest_];+    stream[closeRequest_] = undefined;+}+function writableStreamMarkFirstWriteRequestInFlight(stream) {+    const writeRequest = stream[writeRequests_].shift();+    stream[inFlightWriteRequest_] = writeRequest;+}+function writableStreamRejectCloseAndClosedPromiseIfNeeded(stream) {+    const closeRequest = stream[closeRequest_];+    if (closeRequest !== undefined) {+        closeRequest.reject(stream[storedError_]);+        stream[closeRequest_] = undefined;+    }+    const writer = stream[writer_];+    if (writer !== undefined) {+        writer[closedPromise_$1].reject(stream[storedError_]);+        writer[closedPromise_$1].promise.catch(() => { });+    }+}+function writableStreamUpdateBackpressure(stream, backpressure) {+    const writer = stream[writer_];+    if (writer !== undefined && backpressure !== stream[backpressure_]) {+        if (backpressure) {+            writer[readyPromise_] = createControlledPromise();+        }+        else {+            writer[readyPromise_].resolve(undefined);+        }+    }+    stream[backpressure_] = backpressure;+}+function isWritableStreamDefaultWriter(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return ownerWritableStream_ in value;+}+function writableStreamDefaultWriterAbort(writer, reason) {+    const stream = writer[ownerWritableStream_];+    return writableStreamAbort(stream, reason);+}+function writableStreamDefaultWriterClose(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return Promise.reject(new TypeError("Writer stream is already closed or errored"));+    }+    const closePromise = createControlledPromise();+    stream[closeRequest_] = closePromise;+    if (stream[backpressure_] && state === "writable") {+        writer[readyPromise_].resolve(undefined);+    }+    writableStreamDefaultControllerClose(stream[writableStreamController_]);+    return closePromise.promise;+}+function writableStreamDefaultWriterCloseWithErrorPropagation(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") {+        return Promise.resolve(undefined);+    }+    if (state === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    return writableStreamDefaultWriterClose(writer);+}+function writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {+    const closedPromise = writer[closedPromise_$1];+    if (closedPromise.state === ControlledPromiseState.Pending) {+        closedPromise.reject(error);+    }+    else {+        writer[closedPromise_$1] = createControlledPromise();+        writer[closedPromise_$1].reject(error);+    }+    writer[closedPromise_$1].promise.catch(() => { });+}+function writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {+    const readyPromise = writer[readyPromise_];+    if (readyPromise.state === ControlledPromiseState.Pending) {+        readyPromise.reject(error);+    }+    else {+        writer[readyPromise_] = createControlledPromise();+        writer[readyPromise_].reject(error);+    }+    writer[readyPromise_].promise.catch(() => { });+}+function writableStreamDefaultWriterGetDesiredSize(writer) {+    const stream = writer[ownerWritableStream_];+    const state = stream[state_];+    if (state === "errored" || state === "erroring") {+        return null;+    }+    if (state === "closed") {+        return 0;+    }+    return writableStreamDefaultControllerGetDesiredSize(stream[writableStreamController_]);+}+function writableStreamDefaultWriterRelease(writer) {+    const stream = writer[ownerWritableStream_];+    const releasedError = new TypeError();+    writableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);+    writableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);+    stream[writer_] = undefined;+    writer[ownerWritableStream_] = undefined;+}+function writableStreamDefaultWriterWrite(writer, chunk) {+    const stream = writer[ownerWritableStream_];+    const controller = stream[writableStreamController_];+    const chunkSize = writableStreamDefaultControllerGetChunkSize(controller, chunk);+    if (writer[ownerWritableStream_] !== stream) {+        return Promise.reject(new TypeError());+    }+    const state = stream[state_];+    if (state === "errored") {+        return Promise.reject(stream[storedError_]);+    }+    if (writableStreamCloseQueuedOrInFlight(stream) || state === "closed") {+        return Promise.reject(new TypeError("Cannot write to a closing or closed stream"));+    }+    if (state === "erroring") {+        return Promise.reject(stream[storedError_]);+    }+    const promise = writableStreamAddWriteRequest(stream);+    writableStreamDefaultControllerWrite(controller, chunk, chunkSize);+    return promise;+}+function setUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, highWaterMark, sizeAlgorithm) {+    if (!isWritableStream(stream)) {+        throw new TypeError();+    }+    if (stream[writableStreamController_] !== undefined) {+        throw new TypeError();+    }+    controller[controlledWritableStream_] = stream;+    stream[writableStreamController_] = controller;+    resetQueue(controller);+    controller[started_$1] = false;+    controller[strategySizeAlgorithm_$1] = sizeAlgorithm;+    controller[strategyHWM_$1] = highWaterMark;+    controller[writeAlgorithm_] = writeAlgorithm;+    controller[closeAlgorithm_] = closeAlgorithm;+    controller[abortAlgorithm_] = abortAlgorithm;+    const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+    writableStreamUpdateBackpressure(stream, backpressure);+    const startResult = startAlgorithm();+    Promise.resolve(startResult).then(_ => {+        controller[started_$1] = true;+        writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+    }, error => {+        controller[started_$1] = true;+        writableStreamDealWithRejection(stream, error);+    });+}+function isWritableStreamDefaultController(value) {+    if (typeof value !== "object" || value === null) {+        return false;+    }+    return controlledWritableStream_ in value;+}+function writableStreamDefaultControllerClearAlgorithms(controller) {+    controller[writeAlgorithm_] = undefined;+    controller[closeAlgorithm_] = undefined;+    controller[abortAlgorithm_] = undefined;+    controller[strategySizeAlgorithm_$1] = undefined;+}+function writableStreamDefaultControllerClose(controller) {+    enqueueValueWithSize(controller, "close", 0);+    writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+}+function writableStreamDefaultControllerGetChunkSize(controller, chunk) {+    let chunkSize;+    try {+        chunkSize = controller[strategySizeAlgorithm_$1](chunk);+    }+    catch (error) {+        writableStreamDefaultControllerErrorIfNeeded(controller, error);+        chunkSize = 1;+    }+    return chunkSize;+}+function writableStreamDefaultControllerGetDesiredSize(controller) {+    return controller[strategyHWM_$1] - controller[queueTotalSize_];+}+function writableStreamDefaultControllerWrite(controller, chunk, chunkSize) {+    try {+        enqueueValueWithSize(controller, { chunk }, chunkSize);+    }+    catch (error) {+        writableStreamDefaultControllerErrorIfNeeded(controller, error);+        return;+    }+    const stream = controller[controlledWritableStream_];+    if (!writableStreamCloseQueuedOrInFlight(stream) && stream[state_] === "writable") {+        const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+        writableStreamUpdateBackpressure(stream, backpressure);+    }+    writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+}+function writableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {+    if (!controller[started_$1]) {+        return;+    }+    const stream = controller[controlledWritableStream_];+    if (stream[inFlightWriteRequest_] !== undefined) {+        return;+    }+    const state = stream[state_];+    if (state === "closed" || state === "errored") {+        return;+    }+    if (state === "erroring") {+        writableStreamFinishErroring(stream);+        return;+    }+    if (controller[queue_].length === 0) {+        return;+    }+    const writeRecord = peekQueueValue(controller);+    if (writeRecord === "close") {+        writableStreamDefaultControllerProcessClose(controller);+    }+    else {+        writableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk);+    }+}+function writableStreamDefaultControllerErrorIfNeeded(controller, error) {+    if (controller[controlledWritableStream_][state_] === "writable") {+        writableStreamDefaultControllerError(controller, error);+    }+}+function writableStreamDefaultControllerProcessClose(controller) {+    const stream = controller[controlledWritableStream_];+    writableStreamMarkCloseRequestInFlight(stream);+    dequeueValue(controller);+    const sinkClosePromise = controller[closeAlgorithm_]();+    writableStreamDefaultControllerClearAlgorithms(controller);+    sinkClosePromise.then(_ => {+        writableStreamFinishInFlightClose(stream);+    }, error => {+        writableStreamFinishInFlightCloseWithError(stream, error);+    });+}+function writableStreamDefaultControllerProcessWrite(controller, chunk) {+    const stream = controller[controlledWritableStream_];+    writableStreamMarkFirstWriteRequestInFlight(stream);+    controller[writeAlgorithm_](chunk).then(_ => {+        writableStreamFinishInFlightWrite(stream);+        const state = stream[state_];+        dequeueValue(controller);+        if (!writableStreamCloseQueuedOrInFlight(stream) && state === "writable") {+            const backpressure = writableStreamDefaultControllerGetBackpressure(controller);+            writableStreamUpdateBackpressure(stream, backpressure);+        }+        writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);+    }, error => {+        if (stream[state_] === "writable") {+            writableStreamDefaultControllerClearAlgorithms(controller);+        }+        writableStreamFinishInFlightWriteWithError(stream, error);+    });+}+function writableStreamDefaultControllerGetBackpressure(controller) {+    const desiredSize = writableStreamDefaultControllerGetDesiredSize(controller);+    return desiredSize <= 0;+}+function writableStreamDefaultControllerError(controller, error) {+    const stream = controller[controlledWritableStream_];+    writableStreamDefaultControllerClearAlgorithms(controller);+    writableStreamStartErroring(stream, error);+}++class ReadableStreamDefaultReader {+    constructor(stream) {+        if (!isReadableStream(stream)) {+            throw new TypeError();+        }+        if (isReadableStreamLocked(stream)) {+            throw new TypeError("The stream is locked.");+        }+        readableStreamReaderGenericInitialize(this, stream);+        this[readRequests_] = [];+    }+    get closed() {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        return this[closedPromise_].promise;+    }+    cancel(reason) {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        const stream = this[ownerReadableStream_];+        if (stream === undefined) {+            return Promise.reject(new TypeError("Reader is not associated with a stream"));+        }+        return readableStreamCancel(stream, reason);+    }+    read() {+        if (!isReadableStreamDefaultReader(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerReadableStream_] === undefined) {+            return Promise.reject(new TypeError("Reader is not associated with a stream"));+        }+        return readableStreamDefaultReaderRead(this, true);+    }+    releaseLock() {+        if (!isReadableStreamDefaultReader(this)) {+            throw new TypeError();+        }+        if (this[ownerReadableStream_] === undefined) {+            return;+        }+        if (this[readRequests_].length !== 0) {+            throw new TypeError("Cannot release a stream with pending read requests");+        }+        readableStreamReaderGenericRelease(this);+    }+}++class WritableStreamDefaultWriter {+    constructor(stream) {+        if (!isWritableStream(stream)) {+            throw new TypeError();+        }+        if (isWritableStreamLocked(stream)) {+            throw new TypeError("Stream is already locked");+        }+        this[ownerWritableStream_] = stream;+        stream[writer_] = this;+        const readyPromise = createControlledPromise();+        const closedPromise = createControlledPromise();+        this[readyPromise_] = readyPromise;+        this[closedPromise_$1] = closedPromise;+        const state = stream[state_];+        if (state === "writable") {+            if (!writableStreamCloseQueuedOrInFlight(stream) && stream[backpressure_]) ;+            else {+                readyPromise.resolve(undefined);+            }+        }+        else if (state === "erroring") {+            readyPromise.reject(stream[storedError_]);+            readyPromise.promise.catch(() => { });+        }+        else if (state === "closed") {+            readyPromise.resolve(undefined);+            closedPromise.resolve(undefined);+        }+        else {+            const storedError = stream[storedError_];+            readyPromise.reject(storedError);+            readyPromise.promise.catch(() => { });+            closedPromise.reject(storedError);+            closedPromise.promise.catch(() => { });+        }+    }+    abort(reason) {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerWritableStream_] === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        return writableStreamDefaultWriterAbort(this, reason);+    }+    close() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        const stream = this[ownerWritableStream_];+        if (stream === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        if (writableStreamCloseQueuedOrInFlight(stream)) {+            return Promise.reject(new TypeError());+        }+        return writableStreamDefaultWriterClose(this);+    }+    releaseLock() {+        const stream = this[ownerWritableStream_];+        if (stream === undefined) {+            return;+        }+        writableStreamDefaultWriterRelease(this);+    }+    write(chunk) {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        if (this[ownerWritableStream_] === undefined) {+            return Promise.reject(new TypeError("Writer is not connected to a stream"));+        }+        return writableStreamDefaultWriterWrite(this, chunk);+    }+    get closed() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        return this[closedPromise_$1].promise;+    }+    get desiredSize() {+        if (!isWritableStreamDefaultWriter(this)) {+            throw new TypeError();+        }+        if (this[ownerWritableStream_] === undefined) {+            throw new TypeError("Writer is not connected to stream");+        }+        return writableStreamDefaultWriterGetDesiredSize(this);+    }+    get ready() {+        if (!isWritableStreamDefaultWriter(this)) {+            return Promise.reject(new TypeError());+        }+        return this[readyPromise_].promise;+    }+}++function pipeTo(source, dest, options) {+    const preventClose = !!options.preventClose;+    const preventAbort = !!options.preventAbort;+    const preventCancel = !!options.preventCancel;+    const signal = options.signal;+    let shuttingDown = false;+    let latestWrite = Promise.resolve();+    const promise = createControlledPromise();+    const reader = new ReadableStreamDefaultReader(source);+    const writer = new WritableStreamDefaultWriter(dest);+    let abortAlgorithm;+    if (signal !== undefined) {+        abortAlgorithm = () => {+            const error = new DOMException("Aborted", "AbortError");+            const actions = [];+            if (preventAbort === false) {+                actions.push(() => {+                    if (dest[state_] === "writable") {+                        return writableStreamAbort(dest, error);+                    }+                    return Promise.resolve();+                });+            }+            if (preventCancel === false) {+                actions.push(() => {+                    if (source[state_] === "readable") {+                        return readableStreamCancel(source, error);+                    }+                    return Promise.resolve();+                });+            }+            shutDown(() => {+                return Promise.all(actions.map(a => a())).then(_ => undefined);+            }, { actualError: error });+        };+        if (signal.aborted === true) {+            abortAlgorithm();+        }+        else {+            signal.addEventListener("abort", abortAlgorithm);+        }+    }+    function onStreamErrored(stream, promise, action) {+        if (stream[state_] === "errored") {+            action(stream[storedError_]);+        }+        else {+            promise.catch(action);+        }+    }+    function onStreamClosed(stream, promise, action) {+        if (stream[state_] === "closed") {+            action();+        }+        else {+            promise.then(action);+        }+    }+    onStreamErrored(source, reader[closedPromise_].promise, error => {+        if (!preventAbort) {+            shutDown(() => writableStreamAbort(dest, error), { actualError: error });+        }+        else {+            shutDown(undefined, { actualError: error });+        }+    });+    onStreamErrored(dest, writer[closedPromise_$1].promise, error => {+        if (!preventCancel) {+            shutDown(() => readableStreamCancel(source, error), { actualError: error });+        }+        else {+            shutDown(undefined, { actualError: error });+        }+    });+    onStreamClosed(source, reader[closedPromise_].promise, () => {+        if (!preventClose) {+            shutDown(() => writableStreamDefaultWriterCloseWithErrorPropagation(writer));+        }+        else {+            shutDown();+        }+    });+    if (writableStreamCloseQueuedOrInFlight(dest) || dest[state_] === "closed") {+        const destClosed = new TypeError();+        if (!preventCancel) {+            shutDown(() => readableStreamCancel(source, destClosed), { actualError: destClosed });+        }+        else {+            shutDown(undefined, { actualError: destClosed });+        }+    }+    function awaitLatestWrite() {+        const curLatestWrite = latestWrite;+        return latestWrite.then(() => curLatestWrite === latestWrite ? undefined : awaitLatestWrite());+    }+    function flushRemainder() {+        if (dest[state_] === "writable" && (!writableStreamCloseQueuedOrInFlight(dest))) {+            return awaitLatestWrite();+        }+        else {+            return undefined;+        }+    }+    function shutDown(action, error) {+        if (shuttingDown) {+            return;+        }+        shuttingDown = true;+        if (action === undefined) {+            action = () => Promise.resolve();+        }+        function finishShutDown() {+            action().then(_ => finalize(error), newError => finalize({ actualError: newError }));+        }+        const flushWait = flushRemainder();+        if (flushWait) {+            flushWait.then(finishShutDown);+        }+        else {+            finishShutDown();+        }+    }+    function finalize(error) {+        writableStreamDefaultWriterRelease(writer);+        readableStreamReaderGenericRelease(reader);+        if (signal && abortAlgorithm) {+            signal.removeEventListener("abort", abortAlgorithm);+        }+        if (error) {+            promise.reject(error.actualError);+        }+        else {+            promise.resolve(undefined);+        }+    }+    function next() {+        if (shuttingDown) {+            return;+        }+        writer[readyPromise_].promise.then(() => {+            readableStreamDefaultReaderRead(reader).then(({ value, done }) => {+                if (done) {+                    return;+                }+                latestWrite = writableStreamDefaultWriterWrite(writer, value).catch(() => { });+                next();+            }, _error => {+                latestWrite = Promise.resolve();+            });+        });+    }+    if (!shuttingDown) {+        next();+    }+    return promise.promise;+}++class ReadableStreamDefaultController {+    constructor() {+        throw new TypeError();+    }+    get desiredSize() {+        ret

Yeah it's intense.

Most of it is necessary to support req.clone() and resp.clone(), which both use stream.tee().

This is mostly why I want you all looking at it early, it's basically going from some interfaces to a complete whatwg streams implementation. You could arguably avoid the transform stream code but I think dropping any of that makes fetch less useful.

mrkurt

comment created time in 20 days

Pull request review commentdenoland/deno

Global request response

+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.+import { test, assert, assertEquals } from "./test_util.ts";++test(function initFromRequest(): void {+  const r = new Request("https://example.com", {+    body: "ahoyhoy",+    method: "post"+  });+  const req = new Request(r);++  // @ts-ignore+  assertEquals(req.bodySource, r.bodySource);+  assertEquals(req.url, "https://example.com");

No but I'll definitely add some fetch test cases that do!

mrkurt

comment created time in 20 days

PR opened denoland/deno

[WIP] Global request response

This is a partial PR for #2108, I want to make sure it's a good path before finishing it up.

For context, these are ports of the Request and Response classes from github.com/superfly/fly

  1. These are heavily dependent on the what-wg streams, which came from this library https://github.com/stardazed/sd-streams
  • How should I vendor this?
  • Should these implement deno.Reader?
  1. Right now, fetch uses an internal Response and Body implementation. Do you all want to keep that as is or make it use this same Response class?
  2. We extended Request in our own implementation to include a remoteAddr, and also made a bunch of props optional that don't make sense outside of a browser. I'd like to extend the types in deno to match.
+2935 -12

0 comment

8 changed files

pr created time in 20 days

push eventsuperfly/deno

Kurt

commit sha 062bd2d714351197dac3ef570826a7bfcf56b642

request as a global, one basic test for it

view details

Kurt

commit sha 429da492cfa0ba847c5944fd313ec156a3c81f69

Fix stream types

view details

push time in 20 days

push eventsuperfly/deno

Kurt

commit sha 54dacad838df815f8d0218cfe1a8ff14bac16a8e

request/response build now

view details

push time in 20 days

create barnchsuperfly/deno

branch : global-request-response

created branch time in 20 days

push eventsuperfly/deno

Ryan Dahl

commit sha ee24254bade280ea3c0121c074951396863393ac

Rename EnvPair to KeyValue.

view details

Ryan Dahl

commit sha 6446bc532840319ac9603c016e2ef419094fdeec

Move fetch headers into its own file.

view details

Bert Belder

commit sha a4b514615796b9b4a2cac1b73935304447897805

build: infer label name for versioned Rust crates

view details

Bert Belder

commit sha bf729a7446970b970ea546b9d1ba751be79df0cb

third_party: add unwanted crates and cargo caches to .gitignore And some other minor clean-ups in the same file.

view details

Bert Belder

commit sha a244c1627031462cd595ca7985b23f9ffe5edf59

third_party: upgrade Rust crates

view details

Bert Belder

commit sha b9914c31139546336beed45b4764777fd6a5fcd3

third_party: add tokio-process Rust crate and its dependencies

view details

Nisheet Sinvhal

commit sha 2cf3a89f63c7bc7cfd9404f779b796c29c8e9598

Add documentation as per #1105 (#1116)

view details

Kitson Kelly

commit sha 765f229357587fb66dfe04d3c48d62c6aae9ce71

Improve robustness of lib builder.

view details

Andy Hayden

commit sha 1241b8e9babfec3e87c8958e2065966ee5dd1335

Fix clippy warnings (#1149) Run with: cargo clippy https://github.com/rust-lang-nursery/rust-clippy

view details

Kyra

commit sha e93d686e9d5e797f7e4e02bda56a8b6d535326ca

Web APIs: `File` and `FormData` (#1056)

view details

Kitson Kelly

commit sha 4e07783663d51877e7d41465cf5ef10d1540c4b3

Improve integration test harness (#1142)

view details

Ryan Dahl

commit sha bd88e56cbc6e64da471b379f996bac6c564a7e1e

Add deno.Buffer (#1121) Do not confuse this with Node's Buffer. This is a direct port of Go's bytes.Buffer - it allows buffering of Reader and Writer objects.

view details

Kitson Kelly

commit sha 5e48a681c4d6d6cb3debb4024b5108780dbbad90

Fix issue with runtime lib generation.

view details

Andy Hayden

commit sha 27ecfc1617c79d23255e025fcbd0257b3523906a

Add repl (#998) - Running repl from js side. - Add tests for repl behavior. - Handle ctrl-C and ctrl-D.

view details

Ryan Dahl

commit sha b3400d822f6e9a1100e693cc06cd09c8249d4422

Decode main.js.map during snapshotting. Pro: time ./out/debug/deno tests/error_001.ts 3.0s -> 0.4s Con: time ./tool/build.py snapshot 33s -> 1m52s out/debug/gen/snapshot_deno.bin 39M -> 121M

view details

Kitson Kelly

commit sha 5c51cffacfab777eed6c5eb5135a3168dcea37ef

Omit sources from source maps in bundle.

view details

Ryan Dahl

commit sha e1d5f82d36f08b9c7a7c6233b7ce354a5cf82836

v0.1.11 - Performance and stability improvements on all platforms. - Add repl (#998) - Add deno.Buffer (#1121) - Support cargo check (#1128) - Upgrade Rust crates and Flatbuffers. (#1145, #1127) - Add helper to turn deno.Reader into async iterator (#1130) - Add ability to load JSON as modules (#1065) - Add deno.resources() (#1119) - Add application/x-typescript mime type support (#1111)

view details

Andy Hayden

commit sha 7a17e2aec6307d37b7fe3bd9c7af0beb15ec924b

Remove flags::process It was doing two independent things: - print help and exit - set log level It's better to do those explicitly in main.rs

view details

Kitson Kelly

commit sha f477b45a0a398e379ecafd2525c460f2793a43c2

Improve preparing stack traces

view details

Andy Hayden

commit sha 13e1eb2b87c146a8594e7e6f24ba738bff116246

Fix many of the clippy::pedantic warnings

view details

push time in 21 days

push eventsuperfly/fly-on-deno

Kurt

commit sha b06b5f9a38fcd2d9529e42e69a72b56634d66585

Proxy kinda works with local Request/Response objects as globals

view details

push time in 21 days

issue commentdenoland/deno

Possible to define globals?

@ry I don't! I also looked for a bit, and realized there's more missing than I thought. I'm working on running the ones we use for fly.io to see how they are, it's possible they'd be good options to include in deno — although your FormData is better:

https://github.com/superfly/fly/blob/master/packages/v8env/src/body_mixin.ts https://github.com/superfly/fly/blob/master/packages/v8env/src/request.ts https://github.com/superfly/fly/blob/master/packages/v8env/src/response.ts

mrkurt

comment created time in 23 days

issue closeddenoland/deno

Possible to define globals?

I'm using some external libraries that expect certain globals (related to #2108). Can I define new globals in my main somehow?

closed time in 24 days

mrkurt

issue commentdenoland/deno

Possible to define globals?

Ah globalThis did it! Thanks.

mrkurt

comment created time in 24 days

issue openeddenoland/

Possible to define globals?

I'm using some external libraries that expect certain globals (related to #2108). Can I define new globals in my main somehow?

created time in 25 days

issue openeddenoland/

Possible to define globals?

I'm using some external libraries that expect certain globals (related to #2108). Can I define new globals in my main somehow?

created time in 25 days

push eventsuperfly/fly-on-deno

Kurt

commit sha 516be814eb079188457508ab02e6e46a7cbcac8c

More :boom: in README

view details

push time in 25 days

create barnchsuperfly/fly-on-deno

branch : master

created branch time in a month

created repositorysuperfly/fly-on-deno

created time in a month

push eventsuperfly/dns-help

Kurt

commit sha a6cdc3d9c813b12f7d3f9af618bb341055497e1d

basic fly app for serving up specific provider docs

view details

push time in a month

push eventsuperfly/dns-help

Kurt

commit sha 9afc713c20b7ac6ae73fb0853e39f0f4c3e8b17a

more organizing

view details

push time in a month

push eventsuperfly/dns-help

Kurt

commit sha 1a6458c22c5117a50e5d46c09e468b4c9478fbde

shuffling some providers

view details

push time in a month

push eventsuperfly/fly

Kurt

commit sha bb59bdab72e352d723f57e61fd205c72cdddefdb

chore(release): v0.50.2-pre.2

view details

push time in a month

created tagsuperfly/fly

tagv0.50.2-pre.2

Fly is a runtime for global applications. Use it to build CDNs, smart proxy applications, and be a little more geo-neutral.

created time in a month

push eventsuperfly/fly

Kurt

commit sha 52779e050c2ee514bf5a115c4f72c4e3a4de277c

fix: crash caused by http parse error after error handler removed

view details

push time in a month

push eventsuperfly/fly

Kurt

commit sha 8a93e6b7445467bc48d1e334e46cf10459aa8541

chore(release): v0.50.2-pre.1

view details

push time in a month

created tagsuperfly/fly

tagv0.50.2-pre.1

Fly is a runtime for global applications. Use it to build CDNs, smart proxy applications, and be a little more geo-neutral.

created time in a month

push eventsuperfly/fly

Kurt

commit sha 01ee4663a0bdafaa3a432313de77a8b73423e0b2

fix: host header edge cases

view details

push time in a month

push eventsuperfly/fly

Kurt

commit sha 66307efdd6fea7932dc821861a850c26baba3f7e

chore(release): v0.50.2-pre.0

view details

push time in a month

push eventsuperfly/fly

Kurt

commit sha 6459fdc56d84d414f142b9f861e67af288b9630e

fix: remove special handling for host header

view details

push time in a month

created tagsuperfly/fly

tagv0.50.1-pre.0

Fly is a runtime for global applications. Use it to build CDNs, smart proxy applications, and be a little more geo-neutral.

created time in a month

push eventsuperfly/fly

Kurt

commit sha 33e698998aa1b2df25299a0d986eb32c2368b98b

fix: don't combine headers if we don't have to

view details

push time in a month

push eventsuperfly/edge

Kurt

commit sha 1bca4f929d587c4686d748d22c48d1832d6f22e7

chore(release): 0.8.0

view details

push time in a month

created tagsuperfly/edge

tagv0.8.0

A set of useful libraries for Edge Apps. Run locally, write tests, and integrate it into your deployment process. Move fast and maybe don't break things? Because, gosh darnit, you're an adult.

created time in a month

push eventsuperfly/edge

Kurt

commit sha c35213ff72afe8e2a488b17f0821dd82b2e641b5

feat: allow tls options on proxy builder

view details

push time in a month

created tagsuperfly/fly

tagv0.50.0

Fly is a runtime for global applications. Use it to build CDNs, smart proxy applications, and be a little more geo-neutral.

created time in a month

push eventsuperfly/fly

Kurt

commit sha df05e0606a984dbc3acdf5c062aad035586004e1

chore(release): v0.50.0

view details

push time in a month

push eventsuperfly/fly

Kurt

commit sha ab9b93591d26e0da58739bd92a4b2b9b1c3cb42a

feat: add tls.servername option for fetch

view details

push time in a month

created tagsuperfly/edge

tagv0.7.2

A set of useful libraries for Edge Apps. Run locally, write tests, and integrate it into your deployment process. Move fast and maybe don't break things? Because, gosh darnit, you're an adult.

created time in 2 months

push eventsuperfly/edge

Kurt

commit sha d9e7e6bb2ba1515989afacfa3de81ff99a2d6201

fix: faster installs, fly now a dev dependency

view details

Kurt

commit sha d1cefee9b95505115338c5e8b83e93050288774a

chore(release): 0.7.2

view details

push time in 2 months

push eventsuperfly/fly

Kurt

commit sha 5a2b6c7f188422a8bcf597e2c7a262a878be45a8

fix: fly secrets set <key> --from-file <path> broken

view details

push time in 2 months

push eventsuperfly/edge

Kurt

commit sha 5224ec8a875f3987090601433bfd90340e19e20a

chore(release): 0.7.1

view details

push time in 2 months

created tagsuperfly/edge

tagv0.7.1

A set of useful libraries for Edge Apps. Run locally, write tests, and integrate it into your deployment process. Move fast and maybe don't break things? Because, gosh darnit, you're an adult.

created time in 2 months

push eventsuperfly/edge

Kurt

commit sha c8b56a43ba2a1eba27aee27ab81a1456ec4212c0

fix: proxy supports fetch client certificates

view details

push time in 2 months

created tagsuperfly/edge

tagv0.7.0

A set of useful libraries for Edge Apps. Run locally, write tests, and integrate it into your deployment process. Move fast and maybe don't break things? Because, gosh darnit, you're an adult.

created time in 2 months

push eventsuperfly/edge

Kurt

commit sha a0068dc7c9378f2c8f6b81907c3701000e73aad4

chore(release): 0.7.0

view details

push time in 2 months

delete branch superfly/edge

delete branch : gitlab_pages

delete time in 2 months

delete branch superfly/edge

delete branch : firebase

delete time in 2 months

push eventsuperfly/edge

Christina Keelan Cottrell

commit sha a964be593fcbfd0d2de9d57be5b160ca2a560674

feat: firebase backend (#42)

view details

push time in 2 months

PR merged superfly/edge

add Firebase backend

WIP

  • [x] File named ./src/backends/<backend_type>.ts
  • [x] Backend source includes comments with functional example
  • [x] Tests specific to backend type
  • [x] Config parser wired up + tested src/config/backends.ts
+42 -3

1 comment

4 changed files

KittyBot

pr closed time in 2 months

push eventsuperfly/edge

Christina Keelan Cottrell

commit sha 93ee12dfed5980803613ddcccbcbcb42c89b6252

feat: gitlab pages backend (#43)

view details

Christina Keelan Cottrell

commit sha 282d7628dc9c71c1afd05e2586baf27ca7e800a5

feat: firebase backend

view details

push time in 2 months

push eventsuperfly/edge

Ramin B

commit sha 5e01d8678041883c53894d60b695713da6a58810

fix: relative `proxy` import on s3 backend (#45)

view details

Kurt

commit sha d0aa9c29e83223fadc69de7761ee1fe918d34fac

fix: conflicting fly versions in dev/dependencies

view details

Kurt

commit sha 767a4489c299c29488f69d14260b893b8a1197a2

chore(release): 0.6.0-0

view details

Kurt

commit sha d0a9dec8566e354d762c0ab357acb6dedc118d7d

new repo name

view details

Kurt

commit sha 7f517f42dec58f012992b5667e984ea3eaabe3ca

chore(release): 0.6.0

view details

Kurt

commit sha 20cb8cd470272e1f804f6fc839b684f454fb8747

fixing missed renames in tests

view details

Kurt Mackey

commit sha f3c77e64fbd76cbbd588fc235cceab13bb9f600e

feat: load balancing Latency and health aware load balancing across a list of backends.

view details

Kurt Mackey

commit sha 32a39611462eb65415a6d262ae3004e2565ed084

try testing with GH actions

view details

Kurt

commit sha c2fd0c712eff4a27fd970c71cf991310ebac07e1

relax fly/fly version restriction, bump to latest

view details

Christina Keelan Cottrell

commit sha e0d07ef90a97f1c793e41874347c27398a1123a8

feat: firebase backend

view details

push time in 2 months

push eventsuperfly/edge

Christina Keelan Cottrell

commit sha 93ee12dfed5980803613ddcccbcbcb42c89b6252

feat: gitlab pages backend (#43)

view details

push time in 2 months

PR merged superfly/edge

add Gitlab pages backend

~WIP~

  • [x] File named ./src/backends/<backend_type>.ts
  • [x] Backend source includes comments with functional example
  • [x] Tests specific to backend type
  • [x] Config parser wired up + tested src/config/backends.ts
+227 -2

0 comment

5 changed files

KittyBot

pr closed time in 2 months

push eventsuperfly/edge

Kurt

commit sha c2fd0c712eff4a27fd970c71cf991310ebac07e1

relax fly/fly version restriction, bump to latest

view details

push time in 2 months

push eventsuperfly/edge

Kurt Mackey

commit sha 32a39611462eb65415a6d262ae3004e2565ed084

try testing with GH actions

view details

push time in 2 months

push eventsuperfly/edge

Ramin B

commit sha 5e01d8678041883c53894d60b695713da6a58810

fix: relative `proxy` import on s3 backend (#45)

view details

Kurt

commit sha d0aa9c29e83223fadc69de7761ee1fe918d34fac

fix: conflicting fly versions in dev/dependencies

view details

Kurt

commit sha 767a4489c299c29488f69d14260b893b8a1197a2

chore(release): 0.6.0-0

view details

Kurt

commit sha d0a9dec8566e354d762c0ab357acb6dedc118d7d

new repo name

view details

Kurt

commit sha 7f517f42dec58f012992b5667e984ea3eaabe3ca

chore(release): 0.6.0

view details

Kurt

commit sha 20cb8cd470272e1f804f6fc839b684f454fb8747

fixing missed renames in tests

view details

Kurt Mackey

commit sha f3c77e64fbd76cbbd588fc235cceab13bb9f600e

feat: load balancing Latency and health aware load balancing across a list of backends.

view details

Christina Keelan Cottrell

commit sha fea7596eb31fb475a36bd8e152a3d4fddbcbc58c

feat: gitlab pages backend

view details

push time in 2 months

push eventsuperfly/edge

Kurt Mackey

commit sha f3c77e64fbd76cbbd588fc235cceab13bb9f600e

feat: load balancing Latency and health aware load balancing across a list of backends.

view details

push time in 2 months

PR merged superfly/edge

Load balancer
+447 -0

0 comment

2 changed files

mrkurt

pr closed time in 2 months

push eventsuperfly/edge

Kurt

commit sha 984edd9848a9db02e71d5bcf2fc6519377c62ac5

allow backend list updates on balancer

view details

push time in 2 months

PR opened superfly/edge

Load balancer
+405 -0

0 comment

2 changed files

pr created time in 2 months

push eventsuperfly/edge

Kurt

commit sha 94d790e323345907d17d37325777d9f0bee0cdae

a little cleanup

view details

push time in 2 months

startedJohnSully/KeyDB

started time in 2 months

create barnchsuperfly/edge

branch : load-balancer

created branch time in 2 months

push eventsuperfly/edge

Kurt

commit sha 20cb8cd470272e1f804f6fc839b684f454fb8747

fixing missed renames in tests

view details

push time in 2 months

more