{"version":3,"sources":["../../../packages/core/data/base64-array-buffer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAsE;IAG1F,OAAO,CAAC,MAAM,CAAC,cAAc,CAAuB;IACpD,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAE/B,OAAO,CAAC,MAAM,KAAK,MAAM,GAWxB;IAED;;;;;OAKG;WACW,MAAM,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM;IAqBtD;;;;;OAKG;WACW,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW;CA2BpD","file":"base64-array-buffer.d.ts","sourcesContent":["/**\r\n * Base64ArrayBuffer class to encode/decode.\r\n */\r\nexport class Base64ArrayBuffer {\r\n    private static chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\r\n\r\n    // Use a lookup table to find the index.\r\n    private static lookupInternal = new Uint8Array(256);\r\n    private static scanned = false;\r\n\r\n    private static get lookup() {\r\n        if (Base64ArrayBuffer.scanned) {\r\n            return Base64ArrayBuffer.lookupInternal;\r\n        }\r\n\r\n        for (let i = 0; i < Base64ArrayBuffer.chars.length; i++) {\r\n            Base64ArrayBuffer.lookupInternal[Base64ArrayBuffer.chars.charCodeAt(i)] = i;\r\n        }\r\n\r\n        Base64ArrayBuffer.scanned = true;\r\n        return Base64ArrayBuffer.lookupInternal;\r\n    }\r\n\r\n    /**\r\n     * Encode the array buffer to base64.\r\n     *\r\n     * @param arraybuffer The array buffer.\r\n     * @returns the base64 string.\r\n     */\r\n    public static Encode(arraybuffer: ArrayBuffer): string {\r\n        const bytes = new Uint8Array(arraybuffer);\r\n        const len = bytes.length;\r\n        let base64 = \"\";\r\n\r\n        for (let i = 0; i < len; i += 3) {\r\n            base64 += Base64ArrayBuffer.chars[bytes[i] >> 2];\r\n            base64 += Base64ArrayBuffer.chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];\r\n            base64 += Base64ArrayBuffer.chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];\r\n            base64 += Base64ArrayBuffer.chars[bytes[i + 2] & 63];\r\n        }\r\n\r\n        if ((len % 3) === 2) {\r\n            base64 = base64.substring(0, base64.length - 1) + \"=\";\r\n        } else if (len % 3 === 1) {\r\n            base64 = base64.substring(0, base64.length - 2) + \"==\";\r\n        }\r\n\r\n        return base64;\r\n    }\r\n\r\n    /**\r\n     * Decode the base64 string to array buffer.\r\n     *\r\n     * @param base64 the base64 string.\r\n     * @returns The array buffer.\r\n     */\r\n    public static Decode(base64: string): ArrayBuffer {\r\n        let bufferLength = base64.length * 0.75;\r\n        const len = base64.length;\r\n        if (base64[base64.length - 1] === '=') {\r\n            bufferLength--;\r\n            if (base64[base64.length - 2] === '=') {\r\n                bufferLength--;\r\n            }\r\n        }\r\n\r\n        const arraybuffer = new ArrayBuffer(bufferLength);\r\n        let bytes = new Uint8Array(arraybuffer);\r\n\r\n        let p = 0;\r\n        for (let i = 0; i < len; i += 4) {\r\n            const encoded1 = Base64ArrayBuffer.lookup[base64.charCodeAt(i)];\r\n            const encoded2 = Base64ArrayBuffer.lookup[base64.charCodeAt(i + 1)];\r\n            const encoded3 = Base64ArrayBuffer.lookup[base64.charCodeAt(i + 2)];\r\n            const encoded4 = Base64ArrayBuffer.lookup[base64.charCodeAt(i + 3)];\r\n\r\n            bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);\r\n            bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);\r\n            bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);\r\n        }\r\n\r\n        return arraybuffer;\r\n    }\r\n}\r\n"]}