mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
25 lines
598 B
TypeScript
25 lines
598 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
// This module is browser compatible.
|
|
|
|
import type { Reader } from "@std/io/types";
|
|
|
|
export class MultiReader implements Reader {
|
|
readonly #readers: Reader[];
|
|
#currentIndex = 0;
|
|
|
|
constructor(readers: 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;
|
|
}
|
|
}
|