From 65d9286203cf239f68c6015818e82e8521e600a1 Mon Sep 17 00:00:00 2001 From: Nick Stott Date: Mon, 28 Oct 2019 12:41:36 -0400 Subject: Re-enable basic stream support for fetch bodies (#3192) * Add sd-streams from https://github.com/stardazed/sd-streams/blob/master/packages/streams/src/ * change the interfaces in dom_types to match what sd-streams expects --- .../streams/writable-stream-default-controller.ts | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 cli/js/streams/writable-stream-default-controller.ts (limited to 'cli/js/streams/writable-stream-default-controller.ts') diff --git a/cli/js/streams/writable-stream-default-controller.ts b/cli/js/streams/writable-stream-default-controller.ts new file mode 100644 index 000000000..57ffe08fd --- /dev/null +++ b/cli/js/streams/writable-stream-default-controller.ts @@ -0,0 +1,101 @@ +// TODO reenable this code when we enable writableStreams and transport types +// // Forked from https://github.com/stardazed/sd-streams/tree/8928cf04b035fd02fb1340b7eb541c76be37e546 +// // Copyright (c) 2018-Present by Arthur Langereis - @zenmumbler MIT + +// /** +// * streams/writable-stream-default-controller - WritableStreamDefaultController class implementation +// * Part of Stardazed +// * (c) 2018-Present by Arthur Langereis - @zenmumbler +// * https://github.com/stardazed/sd-streams +// */ + +// /* eslint-disable @typescript-eslint/no-explicit-any */ +// // TODO reenable this lint here + +// import * as ws from "./writable-internals.ts"; +// import * as shared from "./shared-internals.ts"; +// import * as q from "./queue-mixin.ts"; +// import { Queue } from "./queue.ts"; +// import { QueuingStrategySizeCallback } from "../dom_types.ts"; + +// export class WritableStreamDefaultController +// implements ws.WritableStreamDefaultController { +// [ws.abortAlgorithm_]: ws.AbortAlgorithm; +// [ws.closeAlgorithm_]: ws.CloseAlgorithm; +// [ws.controlledWritableStream_]: ws.WritableStream; +// [ws.started_]: boolean; +// [ws.strategyHWM_]: number; +// [ws.strategySizeAlgorithm_]: QueuingStrategySizeCallback; +// [ws.writeAlgorithm_]: ws.WriteAlgorithm; + +// [q.queue_]: Queue | "close">>; +// [q.queueTotalSize_]: number; + +// constructor() { +// throw new TypeError(); +// } + +// error(e?: shared.ErrorResult): void { +// if (!ws.isWritableStreamDefaultController(this)) { +// throw new TypeError(); +// } +// const state = this[ws.controlledWritableStream_][shared.state_]; +// if (state !== "writable") { +// return; +// } +// ws.writableStreamDefaultControllerError(this, e); +// } + +// [ws.abortSteps_](reason: shared.ErrorResult): Promise { +// const result = this[ws.abortAlgorithm_](reason); +// ws.writableStreamDefaultControllerClearAlgorithms(this); +// return result; +// } + +// [ws.errorSteps_](): void { +// q.resetQueue(this); +// } +// } + +// export function setUpWritableStreamDefaultControllerFromUnderlyingSink< +// InputType +// >( +// stream: ws.WritableStream, +// underlyingSink: ws.WritableStreamSink, +// highWaterMark: number, +// sizeAlgorithm: QueuingStrategySizeCallback +// ): void { +// // Assert: underlyingSink is not undefined. +// const controller = Object.create( +// WritableStreamDefaultController.prototype +// ) as WritableStreamDefaultController; + +// const startAlgorithm = function(): any { +// return shared.invokeOrNoop(underlyingSink, "start", [controller]); +// }; +// const writeAlgorithm = shared.createAlgorithmFromUnderlyingMethod( +// underlyingSink, +// "write", +// [controller] +// ); +// const closeAlgorithm = shared.createAlgorithmFromUnderlyingMethod( +// underlyingSink, +// "close", +// [] +// ); +// const abortAlgorithm = shared.createAlgorithmFromUnderlyingMethod( +// underlyingSink, +// "abort", +// [] +// ); +// ws.setUpWritableStreamDefaultController( +// stream, +// controller, +// startAlgorithm, +// writeAlgorithm, +// closeAlgorithm, +// abortAlgorithm, +// highWaterMark, +// sizeAlgorithm +// ); +// } -- cgit v1.2.3