| | const atob = require('atob'); |
| | const btoa = require('btoa'); |
| |
|
| | class Base64Util { |
| |
|
| | |
| | |
| | |
| | |
| | |
| | static base64ToUint8Array (base64) { |
| | const binaryString = atob(base64); |
| | const len = binaryString.length; |
| | const array = new Uint8Array(len); |
| | for (let i = 0; i < len; i++) { |
| | array[i] = binaryString.charCodeAt(i); |
| | } |
| | return array; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | static uint8ArrayToBase64 (array) { |
| | let binary = ''; |
| | const len = array.byteLength; |
| | for (let i = 0; i < len; i++) { |
| | binary += String.fromCharCode(array[i]); |
| | } |
| | return btoa(binary); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | static arrayBufferToBase64 (buffer) { |
| | return Base64Util.uint8ArrayToBase64(new Uint8Array(buffer)); |
| | } |
| |
|
| | } |
| |
|
| | module.exports = Base64Util; |
| |
|