import { Buffer } from "./buffer.ts";
export class StringReader extends Buffer { constructor(s: string) { super(new TextEncoder().encode(s).buffer); }}
export class MultiReader implements Deno.Reader { readonly #readers: Deno.Reader[]; #currentIndex = 0;
constructor(readers: Deno.Reader[]) { this.#readers = [...readers]; }
async read(p: Uint8Array): Promise<number | null> { const r = this.#readers[this.#currentIndex]; if (!r) return null; const result = await r.read(p); if (result === null) { this.#currentIndex++; return 0; } return result; }}
export class LimitedReader implements Deno.Reader { constructor(public reader: Deno.Reader, public limit: number) {}
async read(p: Uint8Array): Promise<number | null> { if (this.limit <= 0) { return null; }
if (p.length > this.limit) { p = p.subarray(0, this.limit); } const n = await this.reader.read(p); if (n == null) { return null; }
this.limit -= n; return n; }}