1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.toBase64 = exports.fromBase64 = void 0;
|
4 | const util_buffer_from_1 = require("@aws-sdk/util-buffer-from");
|
5 | const BASE64_REGEX = /^[A-Za-z0-9+/]*={0,2}$/;
|
6 | function fromBase64(input) {
|
7 | if ((input.length * 3) % 4 !== 0) {
|
8 | throw new TypeError(`Incorrect padding on base64 string.`);
|
9 | }
|
10 | if (!BASE64_REGEX.exec(input)) {
|
11 | throw new TypeError(`Invalid base64 string.`);
|
12 | }
|
13 | const buffer = (0, util_buffer_from_1.fromString)(input, "base64");
|
14 | return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
15 | }
|
16 | exports.fromBase64 = fromBase64;
|
17 | function toBase64(input) {
|
18 | return (0, util_buffer_from_1.fromArrayBuffer)(input.buffer, input.byteOffset, input.byteLength).toString("base64");
|
19 | }
|
20 | exports.toBase64 = toBase64;
|