import { StreamEncoderHelper } from '../stream-helper/encoder.js'; import type { EncodeOptions } from '../options.js'; /** 流式编码 UBJSON */ export class EncodeTransformer implements Transformer> { constructor(options?: EncodeOptions) { this.helper = new StreamEncoderHelper(options, (binary) => { this.controller.enqueue(binary); }); } private readonly helper; private controller!: TransformStreamDefaultController>; /** @inheritdoc */ transform(obj: unknown, controller: TransformStreamDefaultController>): void { this.controller = controller; this.helper.encode(obj); } /** @inheritdoc */ flush(controller: TransformStreamDefaultController>): void { this.controller = controller; this.helper.destroy(); controller.terminate(); } }