export async function collectBlockstoreBytes(input) {
    if (input instanceof Uint8Array) {
        return input;
    }
    const chunks = [];
    let byteLength = 0;
    for await (const chunk of input) {
        chunks.push(chunk);
        byteLength += chunk.byteLength;
    }
    if (chunks.length === 1) {
        return chunks[0];
    }
    const bytes = new Uint8Array(byteLength);
    let offset = 0;
    for (const chunk of chunks) {
        bytes.set(chunk, offset);
        offset += chunk.byteLength;
    }
    return bytes;
}
export async function* yieldBlockstoreBytes(bytes) {
    yield bytes;
}
export async function* putManyBlockstoreItems(blockstore, source, options) {
    for await (const entry of source) {
        await blockstore.put(entry.cid, entry.bytes, options);
        yield entry.cid;
    }
}
export async function* getManyBlockstoreItems(blockstore, source, options) {
    for await (const key of source) {
        yield {
            cid: key,
            bytes: blockstore.get(key, options),
        };
    }
}
export async function* deleteManyBlockstoreItems(blockstore, source, options) {
    for await (const key of source) {
        await blockstore.delete(key, options);
        yield key;
    }
}
//# sourceMappingURL=blockstore-utils.js.map