File tree Expand file tree Collapse file tree 3 files changed +21
-11
lines changed
Expand file tree Collapse file tree 3 files changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -40,37 +40,47 @@ for (var i = 0; i < 64;)
4040 * @returns {string } Base64 encoded string
4141 */
4242base64 . encode = function encode ( buffer , start , end ) {
43- var string = [ ] ; // alt: new Array(Math.ceil((end - start) / 3) * 4);
43+ var parts = null ,
44+ chunk = [ ] ;
4445 var i = 0 , // output index
4546 j = 0 , // goto index
4647 t ; // temporary
4748 while ( start < end ) {
4849 var b = buffer [ start ++ ] ;
4950 switch ( j ) {
5051 case 0 :
51- string [ i ++ ] = b64 [ b >> 2 ] ;
52+ chunk [ i ++ ] = b64 [ b >> 2 ] ;
5253 t = ( b & 3 ) << 4 ;
5354 j = 1 ;
5455 break ;
5556 case 1 :
56- string [ i ++ ] = b64 [ t | b >> 4 ] ;
57+ chunk [ i ++ ] = b64 [ t | b >> 4 ] ;
5758 t = ( b & 15 ) << 2 ;
5859 j = 2 ;
5960 break ;
6061 case 2 :
61- string [ i ++ ] = b64 [ t | b >> 6 ] ;
62- string [ i ++ ] = b64 [ b & 63 ] ;
62+ chunk [ i ++ ] = b64 [ t | b >> 6 ] ;
63+ chunk [ i ++ ] = b64 [ b & 63 ] ;
6364 j = 0 ;
6465 break ;
6566 }
67+ if ( i > 8191 ) {
68+ ( parts || ( parts = [ ] ) ) . push ( String . fromCharCode . apply ( String , chunk ) ) ;
69+ i = 0 ;
70+ }
6671 }
6772 if ( j ) {
68- string [ i ++ ] = b64 [ t ] ;
69- string [ i ] = 61 ;
73+ chunk [ i ++ ] = b64 [ t ] ;
74+ chunk [ i ++ ] = 61 ;
7075 if ( j === 1 )
71- string [ i + 1 ] = 61 ;
76+ chunk [ i ++ ] = 61 ;
77+ }
78+ if ( parts ) {
79+ if ( i )
80+ parts . push ( String . fromCharCode . apply ( String , chunk . slice ( 0 , i ) ) ) ;
81+ return parts . join ( "" ) ;
7282 }
73- return String . fromCharCode . apply ( String , string ) ;
83+ return String . fromCharCode . apply ( String , chunk . slice ( 0 , i ) ) ;
7484} ;
7585
7686var invalidEncoding = "invalid encoding" ;
Original file line number Diff line number Diff line change 11{
22 "name" : " @protobufjs/base64" ,
33 "description" : " A minimal base64 implementation for number arrays." ,
4- "version" : " 1.1.1 " ,
4+ "version" : " 1.1.2 " ,
55 "author" : " Daniel Wirtz <dcode+protobufjs@dcode.io>" ,
66 "repository" : {
77 "type" : " git" ,
Original file line number Diff line number Diff line change 4646 "dependencies" : {
4747 "long" : " ^3.2.0" ,
4848 "@protobufjs/aspromise" : " ^1.1.2" ,
49- "@protobufjs/base64" : " ^1.1.1 " ,
49+ "@protobufjs/base64" : " ^1.1.2 " ,
5050 "@protobufjs/codegen" : " ^2.0.3" ,
5151 "@protobufjs/eventemitter" : " ^1.1.0" ,
5252 "@protobufjs/fetch" : " ^1.1.0" ,
You can’t perform that action at this time.
0 commit comments