import { N as NostrWasm } from './nostr.js';

const sb64_data = "[encoded data, 133484 characters]";

const initNostrWasm = async () => {
    // get bytes blob from base64
    const atu8_gzipped = new Uint8Array(atob(sb64_data)
        .split('')
        .map(s => s.charCodeAt(0)));
    // read it as a gzip file
    const ds_src = new ReadableStream({
        start(d_ctrl) {
            d_ctrl.enqueue(atu8_gzipped);
            d_ctrl.close();
        }
    });
    // and decompress it
    const ds_dst = ds_src.pipeThrough(new DecompressionStream('gzip'));
    const d_reader = ds_dst.getReader();
    const a_chunks = [];
    for (;;) {
        const { value: atu8_chunk, done: b_done } = await d_reader.read();
        if (b_done)
            break;
        a_chunks.push(atu8_chunk);
    }
    const atu8_gunzipped = concat(a_chunks);
    return await NostrWasm(atu8_gunzipped);
};
function concat(a_buffers) {
    let size = 0;
    for (const atu8_each of a_buffers) {
        size += atu8_each.byteLength;
    }
    const atu8_out = new Uint8Array(size);
    let index = 0;
    for (const atu8_each of a_buffers) {
        atu8_out.set(atu8_each, index);
        index += atu8_each.byteLength;
    }
    return atu8_out;
}

export { NostrWasm, initNostrWasm };
