12 lines
414 B
TypeScript
12 lines
414 B
TypeScript
/**
|
|
* Convert a Base64-encoded string into a buffer with the same data.
|
|
* @param base64 The Base64 encoded string.
|
|
*/
|
|
export function base64ToArrayBuffer(base64: string): ArrayBuffer {
|
|
const binaryString = atob(base64);
|
|
const bytes = new Uint8Array(binaryString.length);
|
|
for (let i = 0; i < binaryString.length; i++) {
|
|
bytes[i] = binaryString.charCodeAt(i);
|
|
}
|
|
return bytes.buffer;
|
|
}
|