"use strict";
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m") throw new TypeError("Private method is not writable");
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _MultiReader_readers, _MultiReader_currentIndex;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiReader = void 0;
/**
 * Reader utility for combining multiple readers
 *
 * @deprecated (will be removed after 1.0.0) Use the {@link https://developer.mozilla.org/en-US/docs/Web/API/Streams_API | Web Streams API} instead.
 */
class MultiReader {
    constructor(readers) {
        _MultiReader_readers.set(this, void 0);
        _MultiReader_currentIndex.set(this, 0);
        __classPrivateFieldSet(this, _MultiReader_readers, [...readers], "f");
    }
    async read(p) {
        var _a;
        const r = __classPrivateFieldGet(this, _MultiReader_readers, "f")[__classPrivateFieldGet(this, _MultiReader_currentIndex, "f")];
        if (!r)
            return null;
        const result = await r.read(p);
        if (result === null) {
            __classPrivateFieldSet(this, _MultiReader_currentIndex, (_a = __classPrivateFieldGet(this, _MultiReader_currentIndex, "f"), _a++, _a), "f");
            return 0;
        }
        return result;
    }
}
exports.MultiReader = MultiReader;
_MultiReader_readers = new WeakMap(), _MultiReader_currentIndex = new WeakMap();
