type Reader = Deno.Reader;
export class OneByteReader implements Reader { constructor(readonly r: Reader) {}
async read(p: Uint8Array): Promise<number | Deno.EOF> { if (p.byteLength === 0) { return 0; } if (!(p instanceof Uint8Array)) { throw Error("expected Uint8Array"); } return this.r.read(p.subarray(0, 1)); }}
export class HalfReader implements Reader { constructor(readonly r: Reader) {}
async read(p: Uint8Array): Promise<number | Deno.EOF> { if (!(p instanceof Uint8Array)) { throw Error("expected Uint8Array"); } const half = Math.floor((p.byteLength + 1) / 2); return this.r.read(p.subarray(0, half)); }}
export class ErrTimeout extends Error { constructor() { super("timeout"); this.name = "ErrTimeout"; }}
export class TimeoutReader implements Reader { count = 0; constructor(readonly r: Reader) {}
async read(p: Uint8Array): Promise<number | Deno.EOF> { this.count++; if (this.count === 2) { throw new ErrTimeout(); } return this.r.read(p); }}