import JSONParser from "https://deno.land/x/streamparser_json@v0.0.5/jsonparse.ts#=";
export class EncodeStream<T> extends TransformStream<T, Uint8Array> { constructor() { const encoder = new TextEncoder(); super({ transform(chunk, controller) { controller.enqueue(encoder.encode(JSON.stringify(chunk))); }, }); }}
export class DecodeStream<T> extends TransformStream<Uint8Array, T> { constructor() { const parser = new JSONParser(); super({ start(controller) { parser.onValue = (value, _key, _parent, stack) => { if (stack.length) return; controller.enqueue(value); }; }, transform(chunk) { parser.write(chunk); }, }); }}