export async function bytesToBase64DataUrl(bytes, type = "application/octet-stream") {
    return await new Promise((resolve, reject) => {
        const reader = Object.assign(new FileReader(), {
            onload: () => resolve(reader.result),
            onerror: () => reject(reader.error),
        });
        reader.readAsDataURL(new File([bytes], "", { type }));
    });
}
export async function arrayBufferToBase64(buffer) {
    var bytes = new Uint8Array(buffer);
    return (await bytesToBase64DataUrl(bytes)).replace("data:application/octet-stream;base64,", "");
}
// async function base64ToArrayBuffer(base64String: string) {
//   let response = await fetch("data:application/octet-stream;base64," + base64String);
//   let arrayBuffer = await response.arrayBuffer();
//   return arrayBuffer;
// }
export async function compressString(input) {
    // Convert the string to a Uint8Array
    const textEncoder = new TextEncoder();
    const inputArray = textEncoder.encode(input);
    // Create a CompressionStream
    const compressionStream = new CompressionStream('gzip');
    const writer = compressionStream.writable.getWriter();
    // Write the data and close the stream
    writer.write(inputArray);
    writer.close();
    // Read the compressed data from the stream
    const compressedArray = await new Response(compressionStream.readable).arrayBuffer();
    // Convert the compressed data to a Uint8Array
    return compressedArray;
}
export async function decompressBuffer(input) {
    const decompressionStream = new DecompressionStream('gzip');
    const writer = decompressionStream.writable.getWriter();
    writer.write(new Uint8Array(input));
    writer.close();
    const decompressedBuffer = await new Response(decompressionStream.readable).arrayBuffer();
    return new TextDecoder().decode(decompressedBuffer);
}
export async function base64ToArrayBuffer(base64) {
    const response = await fetch("data:application/octet-stream;base64," + base64);
    return response.arrayBuffer();
}
// Base58 character set
// const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
// Base58 encoding
// Base58 encoding
// function encodeBase58(buffer: Uint8Array): string {
//   let carry;
//   const digits = [0];
//   for (const byte of buffer) {
//     carry = byte;
//     for (let i = 0; i < digits.length; i++) {
//       carry += digits[i] << 8;
//       digits[i] = carry % 58;
//       carry = Math.floor(carry / 58);
//     }
//     while (carry > 0) {
//       digits.push(carry % 58);
//       carry = Math.floor(carry / 58);
//     }
//   }
//   let result = '';
//   for (const digit of digits.reverse()) {
//     result += BASE58_ALPHABET[digit];
//   }
//   // Handle leading zero bytes
//   for (const byte of buffer) {
//     if (byte === 0x00) {
//       result = BASE58_ALPHABET[0] + result;
//     } else {
//       break;
//     }
//   }
//   return result;
// }
// Convert UUID v4 to Base58
// function uuidToBase58(uuid: string): string {
//   const bytes = uuidToBytes(uuid);
//   return encodeBase58(bytes);
// }
//# sourceMappingURL=dataUtils.js.map