summaryrefslogtreecommitdiff
path: root/cli/js/web/streams/transform_stream_default_controller.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-05-04 05:10:52 +1000
committerGitHub <noreply@github.com>2020-05-03 15:10:52 -0400
commit7e32269f3f230c5b714bbf70aa59d74f9a867373 (patch)
treeacc9d0089d0f16e17357e82e82e2a37db2641bbc /cli/js/web/streams/transform_stream_default_controller.ts
parent1560af2b6ecda4a020d5a1492b824e4bbf622db3 (diff)
Add TransformStream and TransformStreamController (#5042)
Diffstat (limited to 'cli/js/web/streams/transform_stream_default_controller.ts')
-rw-r--r--cli/js/web/streams/transform_stream_default_controller.ts75
1 files changed, 75 insertions, 0 deletions
diff --git a/cli/js/web/streams/transform_stream_default_controller.ts b/cli/js/web/streams/transform_stream_default_controller.ts
new file mode 100644
index 000000000..2fc8d2160
--- /dev/null
+++ b/cli/js/web/streams/transform_stream_default_controller.ts
@@ -0,0 +1,75 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+
+import {
+ FlushAlgorithm,
+ isTransformStreamDefaultController,
+ readableStreamDefaultControllerGetDesiredSize,
+ setFunctionName,
+ TransformAlgorithm,
+ transformStreamDefaultControllerEnqueue,
+ transformStreamDefaultControllerError,
+ transformStreamDefaultControllerTerminate,
+} from "./internals.ts";
+import { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_controller.ts";
+import * as sym from "./symbols.ts";
+import { TransformStreamImpl } from "./transform_stream.ts";
+import { customInspect } from "../console.ts";
+
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export class TransformStreamDefaultControllerImpl<I = any, O = any>
+ implements TransformStreamDefaultController<O> {
+ [sym.controlledTransformStream]: TransformStreamImpl<I, O>;
+ [sym.flushAlgorithm]: FlushAlgorithm;
+ [sym.transformAlgorithm]: TransformAlgorithm<I>;
+
+ private constructor() {
+ throw new TypeError(
+ "TransformStreamDefaultController's constructor cannot be called."
+ );
+ }
+
+ get desiredSize(): number | null {
+ if (!isTransformStreamDefaultController(this)) {
+ throw new TypeError("Invalid TransformStreamDefaultController.");
+ }
+ const readableController = this[sym.controlledTransformStream][
+ sym.readable
+ ][sym.readableStreamController];
+ return readableStreamDefaultControllerGetDesiredSize(
+ readableController as ReadableStreamDefaultControllerImpl<O>
+ );
+ }
+
+ enqueue(chunk: O): void {
+ if (!isTransformStreamDefaultController(this)) {
+ throw new TypeError("Invalid TransformStreamDefaultController.");
+ }
+ transformStreamDefaultControllerEnqueue(this, chunk);
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ error(reason?: any): void {
+ if (!isTransformStreamDefaultController(this)) {
+ throw new TypeError("Invalid TransformStreamDefaultController.");
+ }
+ transformStreamDefaultControllerError(this, reason);
+ }
+
+ terminate(): void {
+ if (!isTransformStreamDefaultController(this)) {
+ throw new TypeError("Invalid TransformStreamDefaultController.");
+ }
+ transformStreamDefaultControllerTerminate(this);
+ }
+
+ [customInspect](): string {
+ return `${this.constructor.name} { desiredSize: ${String(
+ this.desiredSize
+ )} }`;
+ }
+}
+
+setFunctionName(
+ TransformStreamDefaultControllerImpl,
+ "TransformStreamDefaultController"
+);