// 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 - WritableStream class implementation // * Part of Stardazed // * (c) 2018-Present by Arthur Langereis - @zenmumbler // * https://github.com/stardazed/sd-streams // */ // import * as ws from "./writable-internals.ts"; // import * as shared from "./shared-internals.ts"; // import { // WritableStreamDefaultController, // setUpWritableStreamDefaultControllerFromUnderlyingSink // } from "./writable-stream-default-controller.ts"; // import { WritableStreamDefaultWriter } from "./writable-stream-default-writer.ts"; // import { QueuingStrategy, QueuingStrategySizeCallback } from "../dom_types.ts"; // export class WritableStream { // [shared.state_]: ws.WritableStreamState; // [shared.storedError_]: shared.ErrorResult; // [ws.backpressure_]: boolean; // [ws.closeRequest_]: shared.ControlledPromise | undefined; // [ws.inFlightWriteRequest_]: shared.ControlledPromise | undefined; // [ws.inFlightCloseRequest_]: shared.ControlledPromise | undefined; // [ws.pendingAbortRequest_]: ws.AbortRequest | undefined; // [ws.writableStreamController_]: // | ws.WritableStreamDefaultController // | undefined; // [ws.writer_]: ws.WritableStreamDefaultWriter | undefined; // [ws.writeRequests_]: Array>; // constructor( // sink: ws.WritableStreamSink = {}, // strategy: QueuingStrategy = {} // ) { // ws.initializeWritableStream(this); // const sizeFunc = strategy.size; // const stratHWM = strategy.highWaterMark; // if (sink.type !== undefined) { // throw new RangeError("The type of an underlying sink must be undefined"); // } // const sizeAlgorithm = shared.makeSizeAlgorithmFromSizeFunction(sizeFunc); // const highWaterMark = shared.validateAndNormalizeHighWaterMark( // stratHWM === undefined ? 1 : stratHWM // ); // setUpWritableStreamDefaultControllerFromUnderlyingSink( // this, // sink, // highWaterMark, // sizeAlgorithm // ); // } // get locked(): boolean { // if (!ws.isWritableStream(this)) { // throw new TypeError(); // } // return ws.isWritableStreamLocked(this); // } // abort(reason?: shared.ErrorResult): Promise { // if (!ws.isWritableStream(this)) { // return Promise.reject(new TypeError()); // } // if (ws.isWritableStreamLocked(this)) { // return Promise.reject(new TypeError("Cannot abort a locked stream")); // } // return ws.writableStreamAbort(this, reason); // } // getWriter(): ws.WritableStreamWriter { // if (!ws.isWritableStream(this)) { // throw new TypeError(); // } // return new WritableStreamDefaultWriter(this); // } // } // export function createWritableStream( // startAlgorithm: ws.StartAlgorithm, // writeAlgorithm: ws.WriteAlgorithm, // closeAlgorithm: ws.CloseAlgorithm, // abortAlgorithm: ws.AbortAlgorithm, // highWaterMark?: number, // sizeAlgorithm?: QueuingStrategySizeCallback // ): WritableStream { // if (highWaterMark === undefined) { // highWaterMark = 1; // } // if (sizeAlgorithm === undefined) { // sizeAlgorithm = (): number => 1; // } // // Assert: ! IsNonNegativeNumber(highWaterMark) is true. // const stream = Object.create(WritableStream.prototype) as WritableStream< // InputType // >; // ws.initializeWritableStream(stream); // const controller = Object.create( // WritableStreamDefaultController.prototype // ) as WritableStreamDefaultController; // ws.setUpWritableStreamDefaultController( // stream, // controller, // startAlgorithm, // writeAlgorithm, // closeAlgorithm, // abortAlgorithm, // highWaterMark, // sizeAlgorithm // ); // return stream; // }