2020-05-03 15:10:52 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
import {
|
|
|
|
FlushAlgorithm,
|
|
|
|
isTransformStreamDefaultController,
|
|
|
|
readableStreamDefaultControllerGetDesiredSize,
|
|
|
|
TransformAlgorithm,
|
|
|
|
transformStreamDefaultControllerEnqueue,
|
|
|
|
transformStreamDefaultControllerError,
|
|
|
|
transformStreamDefaultControllerTerminate,
|
|
|
|
} from "./internals.ts";
|
2020-07-08 05:26:39 -04:00
|
|
|
import type { ReadableStreamDefaultControllerImpl } from "./readable_stream_default_controller.ts";
|
2020-05-03 15:10:52 -04:00
|
|
|
import * as sym from "./symbols.ts";
|
2020-07-08 05:26:39 -04:00
|
|
|
import type { TransformStreamImpl } from "./transform_stream.ts";
|
2020-05-03 15:10:52 -04:00
|
|
|
import { customInspect } from "../console.ts";
|
2020-07-10 22:38:15 -04:00
|
|
|
import { setFunctionName } from "../util.ts";
|
2020-05-03 15:10:52 -04:00
|
|
|
|
|
|
|
// 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(
|
2020-07-14 15:24:17 -04:00
|
|
|
"TransformStreamDefaultController's constructor cannot be called.",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get desiredSize(): number | null {
|
|
|
|
if (!isTransformStreamDefaultController(this)) {
|
|
|
|
throw new TypeError("Invalid TransformStreamDefaultController.");
|
|
|
|
}
|
|
|
|
const readableController = this[sym.controlledTransformStream][
|
|
|
|
sym.readable
|
|
|
|
][sym.readableStreamController];
|
|
|
|
return readableStreamDefaultControllerGetDesiredSize(
|
2020-07-14 15:24:17 -04:00
|
|
|
readableController as ReadableStreamDefaultControllerImpl<O>,
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2020-07-14 15:24:17 -04:00
|
|
|
return `${this.constructor.name} { desiredSize: ${
|
|
|
|
String(this.desiredSize)
|
|
|
|
} }`;
|
2020-05-03 15:10:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setFunctionName(
|
|
|
|
TransformStreamDefaultControllerImpl,
|
2020-07-14 15:24:17 -04:00
|
|
|
"TransformStreamDefaultController",
|
2020-05-03 15:10:52 -04:00
|
|
|
);
|