@hazae41/base64
Version:
Base64 adapter for WebAssembly and JS implementations
26 lines (23 loc) • 944 B
JavaScript
import { Buffers } from '../../libs/buffers/buffers.mjs';
import { Bytes } from '../../libs/bytes/bytes.mjs';
import { Copied } from '../../libs/copiable/index.mjs';
function fromBuffer() {
function getBytes(bytes) {
return "bytes" in bytes ? bytes.bytes : bytes;
}
function encodePaddedOrThrow(bytes) {
return Buffers.fromView(getBytes(bytes)).toString("base64");
}
function decodePaddedOrThrow(text) {
return new Copied(Bytes.fromView(Buffer.from(text, "base64")));
}
function encodeUnpaddedOrThrow(bytes) {
return Buffers.fromView(getBytes(bytes)).toString("base64").replaceAll("=", "");
}
function decodeUnpaddedOrThrow(text) {
return new Copied(Bytes.fromView(Buffer.from(text, "base64")));
}
return { encodePaddedOrThrow, decodePaddedOrThrow, encodeUnpaddedOrThrow, decodeUnpaddedOrThrow };
}
export { fromBuffer };
//# sourceMappingURL=buffer.mjs.map