File tree 3 files changed +21
-11
lines changed
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;)
40
40
* @returns {string } Base64 encoded string
41
41
*/
42
42
base64 . encode = function encode ( buffer , start , end ) {
43
- var string = [ ] ; // alt: new Array(Math.ceil((end - start) / 3) * 4);
43
+ var parts = null ,
44
+ chunk = [ ] ;
44
45
var i = 0 , // output index
45
46
j = 0 , // goto index
46
47
t ; // temporary
47
48
while ( start < end ) {
48
49
var b = buffer [ start ++ ] ;
49
50
switch ( j ) {
50
51
case 0 :
51
- string [ i ++ ] = b64 [ b >> 2 ] ;
52
+ chunk [ i ++ ] = b64 [ b >> 2 ] ;
52
53
t = ( b & 3 ) << 4 ;
53
54
j = 1 ;
54
55
break ;
55
56
case 1 :
56
- string [ i ++ ] = b64 [ t | b >> 4 ] ;
57
+ chunk [ i ++ ] = b64 [ t | b >> 4 ] ;
57
58
t = ( b & 15 ) << 2 ;
58
59
j = 2 ;
59
60
break ;
60
61
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 ] ;
63
64
j = 0 ;
64
65
break ;
65
66
}
67
+ if ( i > 8191 ) {
68
+ ( parts || ( parts = [ ] ) ) . push ( String . fromCharCode . apply ( String , chunk ) ) ;
69
+ i = 0 ;
70
+ }
66
71
}
67
72
if ( j ) {
68
- string [ i ++ ] = b64 [ t ] ;
69
- string [ i ] = 61 ;
73
+ chunk [ i ++ ] = b64 [ t ] ;
74
+ chunk [ i ++ ] = 61 ;
70
75
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 ( "" ) ;
72
82
}
73
- return String . fromCharCode . apply ( String , string ) ;
83
+ return String . fromCharCode . apply ( String , chunk . slice ( 0 , i ) ) ;
74
84
} ;
75
85
76
86
var invalidEncoding = "invalid encoding" ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @protobufjs/base64" ,
3
3
"description" : " A minimal base64 implementation for number arrays." ,
4
- "version" : " 1.1.1 " ,
4
+ "version" : " 1.1.2 " ,
5
5
"author" :
" Daniel Wirtz <[email protected] >" ,
6
6
"repository" : {
7
7
"type" : " git" ,
Original file line number Diff line number Diff line change 46
46
"dependencies" : {
47
47
"long" : " ^3.2.0" ,
48
48
"@protobufjs/aspromise" : " ^1.1.2" ,
49
- "@protobufjs/base64" : " ^1.1.1 " ,
49
+ "@protobufjs/base64" : " ^1.1.2 " ,
50
50
"@protobufjs/codegen" : " ^2.0.3" ,
51
51
"@protobufjs/eventemitter" : " ^1.1.0" ,
52
52
"@protobufjs/fetch" : " ^1.1.0" ,
You can’t perform that action at this time.
0 commit comments