Tidied up Steganography operations. FileType and toBase64 functions now accept ArrayBuffers.

This commit is contained in:
n1474335 2019-09-04 13:54:59 +01:00
parent 5bc5c0df90
commit eb769c7fb4
28 changed files with 81 additions and 75 deletions

View file

@ -12,7 +12,7 @@ import Utils from "../Utils.mjs";
/**
* Base64's the input byte array using the given alphabet, returning a string.
*
* @param {byteArray|Uint8Array|string} data
* @param {byteArray|Uint8Array|ArrayBuffer|string} data
* @param {string} [alphabet="A-Za-z0-9+/="]
* @returns {string}
*
@ -25,6 +25,9 @@ import Utils from "../Utils.mjs";
*/
export function toBase64(data, alphabet="A-Za-z0-9+/=") {
if (!data) return "";
if (data instanceof ArrayBuffer) {
data = new Uint8Array(data);
}
if (typeof data == "string") {
data = Utils.strToByteArray(data);
}