Use existing util to convert Uint8Array to base64

This commit is contained in:
Jordan Eldredge 2020-12-02 23:36:17 -08:00
parent 3a9d32dfee
commit 8a144eee4b
2 changed files with 7 additions and 7 deletions

View file

@ -1,4 +1,5 @@
import { RIFFFile } from "riff-file";
import * as Utils from "./utils";
import { unpackArray } from "byte-data";
type Chunk = {
@ -75,12 +76,8 @@ function parseMetadata(chunkData: Uint8Array) {
};
}
function base64(u8: Uint8Array): string {
return window.btoa(String.fromCharCode.apply(null, u8));
}
function urlFromData(arr: Uint8Array): string {
const arrBase64 = base64(arr);
const arrBase64 = Utils.base64FromDataArray(arr);
return `data:image/x-win-bitmap;base64,${arrBase64}`;
}

View file

@ -129,9 +129,12 @@ export const parseIni = (text: string): IniData => {
export const clamp = (value: number, min: number, max: number): number =>
Math.min(Math.max(value, min), max);
export const base64FromDataArray = (dataArray: Uint8Array): string => {
return window.btoa(String.fromCharCode(...dataArray));
};
export const base64FromArrayBuffer = (arrayBuffer: ArrayBuffer): string => {
const dataView = new Uint8Array(arrayBuffer);
return window.btoa(String.fromCharCode(...dataView));
return base64FromDataArray(new Uint8Array(arrayBuffer));
};
// https://stackoverflow.com/a/15832662/1263117