MLE functions to work with base64 encoded data (mle-encode-base64)

MLE Base64 Encoding

This module contains code to work with base64-encoded data.

Getting Started

In order to use the base64 module, it needs to be imported first. If executed as a snippet in DBMS_MLE, a dynamic import needs to be used and wrapped within an async function:

const {encode: base64encode, decode: base64decode} = await import('mle-encode-base64');

If used within MLE modules, the regular ECMAScript module import syntax can be used:

import {encode as base64encode, decode as base64decode} from 'mle-encode-base64';

The following example shows how to encode an ASCII string and to decode it again into an ArrayBuffer which can then be converted back into a string using asciiBytesToString:

function asciiBytesToString(bytesBuffer) {
let charCodes = new Uint8Array(bytesBuffer);
let result = "";

charCodes.forEach((char) => {
result += String.fromCharCode(char);
});
return result;
}

const testInput = 'hello';
const encoded = base64encode(input);
console.log('encoded: ' + encoded);
const decodedBytes = base64decode(encoded);
console.log('decoded into an ArrayBuffer?: ' + (decodedBytes instanceof ArrayBuffer));
const stringFromBytes = asciiBytesToString(decodedBytes);
console.log('string from decoded: ' + stringFromBytes);