UNPKG

alinea

Version:
34 lines (32 loc) 1.02 kB
import "../../chunks/chunk-NZLE2WMY.js"; // src/core/util/BufferToBase64.ts import { Blob, CompressionStream, DecompressionStream, Response } from "@alinea/iso"; var decode = (btoa2, format = "deflate") => { const str = atob(btoa2); const { length } = str; const buffer = new Uint8Array(length); for (let i = 0; i < length; i++) buffer[i] = str.charCodeAt(i); const blob = new Blob([buffer]); return (format ? new Response(blob.stream().pipeThrough(new DecompressionStream(format))) : blob).arrayBuffer(); }; var encode = async (buffer, format = "deflate") => { const blob = new Blob([buffer]); const res = format ? new Response(blob.stream().pipeThrough(new CompressionStream(format))) : blob; const view = new Uint8Array(await res.arrayBuffer()); const { fromCharCode } = String; const { length } = view; let out = ""; const c = 2e3; for (let i = 0; i < length; i += c) out += fromCharCode(...view.subarray(i, i + c)); return btoa(out); }; export { decode, encode };