File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change 55 * Copyright (c) 2012 Niklas von Hertzen
66 * Licensed under the MIT license.
77 */
8- ( function ( chars ) {
8+ ( function ( ) {
99 "use strict" ;
1010
11+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ;
12+
13+ // Use a lookup table to find the index.
14+ var lookup = new Uint8Array ( 256 ) ;
15+ for ( var i = 0 ; i < chars . length ; i ++ ) {
16+ lookup [ chars . charCodeAt ( i ) ] = i ;
17+ }
18+
1119 exports . encode = function ( arraybuffer ) {
1220 var bytes = new Uint8Array ( arraybuffer ) ,
1321 i , len = bytes . length , base64 = "" ;
4452 bytes = new Uint8Array ( arraybuffer ) ;
4553
4654 for ( i = 0 ; i < len ; i += 4 ) {
47- encoded1 = chars . indexOf ( base64 [ i ] ) ;
48- encoded2 = chars . indexOf ( base64 [ i + 1 ] ) ;
49- encoded3 = chars . indexOf ( base64 [ i + 2 ] ) ;
50- encoded4 = chars . indexOf ( base64 [ i + 3 ] ) ;
55+ encoded1 = lookup [ base64 . charCodeAt ( i ) ] ;
56+ encoded2 = lookup [ base64 . charCodeAt ( i + 1 ) ] ;
57+ encoded3 = lookup [ base64 . charCodeAt ( i + 2 ) ] ;
58+ encoded4 = lookup [ base64 . charCodeAt ( i + 3 ) ] ;
5159
5260 bytes [ p ++ ] = ( encoded1 << 2 ) | ( encoded2 >> 4 ) ;
5361 bytes [ p ++ ] = ( ( encoded2 & 15 ) << 4 ) | ( encoded3 >> 2 ) ;
5664
5765 return arraybuffer ;
5866 } ;
59- } ) ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ) ;
67+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments