10 examples of 'base64 to binary javascript' in JavaScript

Every line of 'base64 to binary javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
505export function binaryToBase64(binArray: number[], base64Pad?: string) {
506 base64Pad = base64Pad || "";
507
508 let result = "";
509 for (let i = 0; i < binArray.length * 4; i += 3) {
510 const triplet = (((binArray[i >> 2] >> 8 * (i % 4)) & 0xFF) << 16) | (((binArray[i + 1 >> 2] >> 8 * ((i + 1) % 4)) & 0xFF) << 8) | ((binArray[i + 2 >> 2] >> 8 * ((i + 2) % 4)) & 0xFF);
511 for (let j = 0; j < 4; j++) {
512 result += i * 8 + j * 6 > binArray.length * 32 ? base64Pad : ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt((triplet >> 6 * (3 - j)) & 0x3F));
513 }
514 }
515 return result;
516}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

171function convertBase64ToBinary (dataURI){
172 var BASE64_MARKER = ';base64,';
173
174 var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
175 var base64 = dataURI.substring(base64Index);
176 var raw = window.atob(base64);
177 var rawLength = raw.length;
178 var array = new Uint8Array(new ArrayBuffer(rawLength));
179
180 for(var i = 0; i < rawLength; i++) {
181 array[i] = raw.charCodeAt(i);
182 }
183 return array;
184 };
14function _arrayBufferToBase64(buffer) {
15 var binary = '';
16 var bytes = new Uint8Array(buffer);
17 var len = bytes.byteLength;
18 for (var i = 0; i < len; i++) {
19 binary += String.fromCharCode(bytes[i]);
20 }
21 return btoa(binary);
22}
18function arrayBufferToBase64(buffer) {
19 let binary = "";
20 const bytes = new Uint8Array(buffer);
21 const len = bytes.byteLength;
22 for (let i = 0; i < len; i += 1) {
23 binary += String.fromCharCode(bytes[i]);
24 }
25 return window.btoa(binary);
26}
38function _arrayBufferToBase64( buffer ) {
39 var binary = '';
40 var bytes = new Uint8Array( buffer );
41 var len = bytes.byteLength;
42 for (var i = 0; i < len; i++) {
43 binary += String.fromCharCode( bytes[ i ] );
44 }
45 return window.btoa( binary );
46}
8function _arrayBufferToBase64(buffer) {
9 var binary = '';
10 var bytes = new Uint8Array(buffer);
11 var len = bytes.byteLength;
12 for (var i = 0; i < len; i++) {
13 binary += String.fromCharCode(bytes[i]);
14 }
15 return btoa(binary);
16}
110function arrayBufferToBase64(buffer) {
111 var bytes = new Uint8Array(buffer);
112 var binary = asciiEncode(bytes);
113 return window.btoa(binary);
114}
49function arrayBufferToBase64( buffer ) {
50 var binary = '';
51 var bytes = new Uint8Array( buffer );
52 var len = bytes.byteLength;
53 for (var i = 0; i < len; i++) {
54 binary += String.fromCharCode( bytes[ i ] );
55 }
56 return window.btoa( binary );
57}
98function arrayBufferToBase64(buffer) {
99 var bytes = new Uint8Array(buffer);
100 var len = bytes.byteLength;
101 var binary = '';
102 for (var i = 0; i < len; i++)
103 binary += String.fromCharCode(bytes[i]);
104 return window.btoa(binary);
105}
4function arrayBufferToBase64 (buffer) {
5 let binary = ''
6 let bytes = new Uint8Array(buffer)
7 let len = bytes.byteLength
8 for (let i = 0; i < len; i++) {
9 binary += String.fromCharCode(bytes[i])
10 }
11 return window.btoa(binary)
12}

Related snippets