import { Buffer } from "./buffer.ts";
export class StringReader extends Buffer {
    constructor(s) {
        super(new TextEncoder().encode(s).buffer);
    }
}
export class MultiReader {
    readers;
    currentIndex = 0;
    constructor(...readers) {
        this.readers = readers;
    }
    async read(p) {
        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 {
    reader;
    limit;
    constructor(reader, limit) {
        this.reader = reader;
        this.limit = limit;
    }
    async read(p) {
        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;
    }
}
//# sourceMappingURL=data:application/json;base64,[encoded data, 4160 characters]