1
- ( function ( f ) { if ( typeof exports === "object" && typeof module !== "undefined" ) { module . exports = f ( ) } else if ( typeof define === "function" && define . amd ) { define ( [ ] , f ) } else { var g ; if ( typeof window !== "undefined" ) { g = window } else if ( typeof global !== "undefined" ) { g = global } else if ( typeof self !== "undefined" ) { g = self } else { g = this } g . plist = f ( ) } } ) ( function ( ) { var define , module , exports ; return ( function ( ) { function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ? n : e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } return e } ) ( ) ( { 1 :[ function ( require , module , exports ) {
2
- ( function ( Buffer ) {
1
+ ( function ( f ) { if ( typeof exports === "object" && typeof module !== "undefined" ) { module . exports = f ( ) } else if ( typeof define === "function" && define . amd ) { define ( [ ] , f ) } else { var g ; if ( typeof window !== "undefined" ) { g = window } else if ( typeof global !== "undefined" ) { g = global } else if ( typeof self !== "undefined" ) { g = self } else { g = this } g . plist = f ( ) } } ) ( function ( ) { var define , module , exports ; return ( function ( ) { function r ( e , n , t ) { function o ( i , f ) { if ( ! n [ i ] ) { if ( ! e [ i ] ) { var c = "function" == typeof require && require ; if ( ! f && c ) return c ( i , ! 0 ) ; if ( u ) return u ( i , ! 0 ) ; var a = new Error ( "Cannot find module '" + i + "'" ) ; throw a . code = "MODULE_NOT_FOUND" , a } var p = n [ i ] = { exports :{ } } ; e [ i ] [ 0 ] . call ( p . exports , function ( r ) { var n = e [ i ] [ 1 ] [ r ] ; return o ( n || r ) } , p , p . exports , r , e , n , t ) } return n [ i ] . exports } for ( var u = "function" == typeof require && require , i = 0 ; i < t . length ; i ++ ) o ( t [ i ] ) ; return o } return r } ) ( ) ( { 1 :[ function ( require , module , exports ) {
2
+ ( function ( Buffer ) { ( function ( ) {
3
3
/**
4
4
* Module dependencies.
5
5
*/
@@ -138,7 +138,7 @@ function walk_obj(next, next_child) {
138
138
}
139
139
}
140
140
141
- } ) . call ( this , { "isBuffer" :require ( "../node_modules/is-buffer/index.js" ) } )
141
+ } ) . call ( this ) } ) . call ( this , { "isBuffer" :require ( "../node_modules/is-buffer/index.js" ) } )
142
142
} , { "../node_modules/is-buffer/index.js" :3 , "base64-js" :2 , "xmlbuilder" :25 } ] , 2 :[ function ( require , module , exports ) {
143
143
'use strict'
144
144
@@ -161,65 +161,98 @@ for (var i = 0, len = code.length; i < len; ++i) {
161
161
revLookup [ '-' . charCodeAt ( 0 ) ] = 62
162
162
revLookup [ '_' . charCodeAt ( 0 ) ] = 63
163
163
164
- function placeHoldersCount ( b64 ) {
164
+ function getLens ( b64 ) {
165
165
var len = b64 . length
166
+
166
167
if ( len % 4 > 0 ) {
167
168
throw new Error ( 'Invalid string. Length must be a multiple of 4' )
168
169
}
169
170
170
- // the number of equal signs (place holders)
171
- // if there are two placeholders, than the two characters before it
172
- // represent one byte
173
- // if there is only one, then the three characters before it represent 2 bytes
174
- // this is just a cheap hack to not do indexOf twice
175
- return b64 [ len - 2 ] === '=' ? 2 : b64 [ len - 1 ] === '=' ? 1 : 0
171
+ // Trim off extra bytes after placeholder bytes are found
172
+ // See: https://github.com/beatgammit/base64-js/issues/42
173
+ var validLen = b64 . indexOf ( '=' )
174
+ if ( validLen === - 1 ) validLen = len
175
+
176
+ var placeHoldersLen = validLen === len
177
+ ? 0
178
+ : 4 - ( validLen % 4 )
179
+
180
+ return [ validLen , placeHoldersLen ]
176
181
}
177
182
183
+ // base64 is 4/3 + up to two characters of the original data
178
184
function byteLength ( b64 ) {
179
- // base64 is 4/3 + up to two characters of the original data
180
- return ( b64 . length * 3 / 4 ) - placeHoldersCount ( b64 )
185
+ var lens = getLens ( b64 )
186
+ var validLen = lens [ 0 ]
187
+ var placeHoldersLen = lens [ 1 ]
188
+ return ( ( validLen + placeHoldersLen ) * 3 / 4 ) - placeHoldersLen
189
+ }
190
+
191
+ function _byteLength ( b64 , validLen , placeHoldersLen ) {
192
+ return ( ( validLen + placeHoldersLen ) * 3 / 4 ) - placeHoldersLen
181
193
}
182
194
183
195
function toByteArray ( b64 ) {
184
- var i , l , tmp , placeHolders , arr
185
- var len = b64 . length
186
- placeHolders = placeHoldersCount ( b64 )
196
+ var tmp
197
+ var lens = getLens ( b64 )
198
+ var validLen = lens [ 0 ]
199
+ var placeHoldersLen = lens [ 1 ]
187
200
188
- arr = new Arr ( ( len * 3 / 4 ) - placeHolders )
201
+ var arr = new Arr ( _byteLength ( b64 , validLen , placeHoldersLen ) )
189
202
190
- // if there are placeholders, only get up to the last complete 4 chars
191
- l = placeHolders > 0 ? len - 4 : len
203
+ var curByte = 0
192
204
193
- var L = 0
205
+ // if there are placeholders, only get up to the last complete 4 chars
206
+ var len = placeHoldersLen > 0
207
+ ? validLen - 4
208
+ : validLen
209
+
210
+ var i
211
+ for ( i = 0 ; i < len ; i += 4 ) {
212
+ tmp =
213
+ ( revLookup [ b64 . charCodeAt ( i ) ] << 18 ) |
214
+ ( revLookup [ b64 . charCodeAt ( i + 1 ) ] << 12 ) |
215
+ ( revLookup [ b64 . charCodeAt ( i + 2 ) ] << 6 ) |
216
+ revLookup [ b64 . charCodeAt ( i + 3 ) ]
217
+ arr [ curByte ++ ] = ( tmp >> 16 ) & 0xFF
218
+ arr [ curByte ++ ] = ( tmp >> 8 ) & 0xFF
219
+ arr [ curByte ++ ] = tmp & 0xFF
220
+ }
194
221
195
- for ( i = 0 ; i < l ; i += 4 ) {
196
- tmp = ( revLookup [ b64 . charCodeAt ( i ) ] << 18 ) | ( revLookup [ b64 . charCodeAt ( i + 1 ) ] << 12 ) | ( revLookup [ b64 . charCodeAt ( i + 2 ) ] << 6 ) | revLookup [ b64 . charCodeAt ( i + 3 ) ]
197
- arr [ L ++ ] = ( tmp >> 16 ) & 0xFF
198
- arr [ L ++ ] = ( tmp >> 8 ) & 0xFF
199
- arr [ L ++ ] = tmp & 0xFF
222
+ if ( placeHoldersLen === 2 ) {
223
+ tmp =
224
+ ( revLookup [ b64 . charCodeAt ( i ) ] << 2 ) |
225
+ ( revLookup [ b64 . charCodeAt ( i + 1 ) ] >> 4 )
226
+ arr [ curByte ++ ] = tmp & 0xFF
200
227
}
201
228
202
- if ( placeHolders === 2 ) {
203
- tmp = ( revLookup [ b64 . charCodeAt ( i ) ] << 2 ) | ( revLookup [ b64 . charCodeAt ( i + 1 ) ] >> 4 )
204
- arr [ L ++ ] = tmp & 0xFF
205
- } else if ( placeHolders === 1 ) {
206
- tmp = ( revLookup [ b64 . charCodeAt ( i ) ] << 10 ) | ( revLookup [ b64 . charCodeAt ( i + 1 ) ] << 4 ) | ( revLookup [ b64 . charCodeAt ( i + 2 ) ] >> 2 )
207
- arr [ L ++ ] = ( tmp >> 8 ) & 0xFF
208
- arr [ L ++ ] = tmp & 0xFF
229
+ if ( placeHoldersLen === 1 ) {
230
+ tmp =
231
+ ( revLookup [ b64 . charCodeAt ( i ) ] << 10 ) |
232
+ ( revLookup [ b64 . charCodeAt ( i + 1 ) ] << 4 ) |
233
+ ( revLookup [ b64 . charCodeAt ( i + 2 ) ] >> 2 )
234
+ arr [ curByte ++ ] = ( tmp >> 8 ) & 0xFF
235
+ arr [ curByte ++ ] = tmp & 0xFF
209
236
}
210
237
211
238
return arr
212
239
}
213
240
214
241
function tripletToBase64 ( num ) {
215
- return lookup [ num >> 18 & 0x3F ] + lookup [ num >> 12 & 0x3F ] + lookup [ num >> 6 & 0x3F ] + lookup [ num & 0x3F ]
242
+ return lookup [ num >> 18 & 0x3F ] +
243
+ lookup [ num >> 12 & 0x3F ] +
244
+ lookup [ num >> 6 & 0x3F ] +
245
+ lookup [ num & 0x3F ]
216
246
}
217
247
218
248
function encodeChunk ( uint8 , start , end ) {
219
249
var tmp
220
250
var output = [ ]
221
251
for ( var i = start ; i < end ; i += 3 ) {
222
- tmp = ( ( uint8 [ i ] << 16 ) & 0xFF0000 ) + ( ( uint8 [ i + 1 ] << 8 ) & 0xFF00 ) + ( uint8 [ i + 2 ] & 0xFF )
252
+ tmp =
253
+ ( ( uint8 [ i ] << 16 ) & 0xFF0000 ) +
254
+ ( ( uint8 [ i + 1 ] << 8 ) & 0xFF00 ) +
255
+ ( uint8 [ i + 2 ] & 0xFF )
223
256
output . push ( tripletToBase64 ( tmp ) )
224
257
}
225
258
return output . join ( '' )
@@ -229,7 +262,6 @@ function fromByteArray (uint8) {
229
262
var tmp
230
263
var len = uint8 . length
231
264
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
232
- var output = ''
233
265
var parts = [ ]
234
266
var maxChunkLength = 16383 // must be multiple of 3
235
267
@@ -241,19 +273,21 @@ function fromByteArray (uint8) {
241
273
// pad the end with zeros, but make sure to not forget the extra bytes
242
274
if ( extraBytes === 1 ) {
243
275
tmp = uint8 [ len - 1 ]
244
- output += lookup [ tmp >> 2 ]
245
- output += lookup [ ( tmp << 4 ) & 0x3F ]
246
- output += '=='
276
+ parts . push (
277
+ lookup [ tmp >> 2 ] +
278
+ lookup [ ( tmp << 4 ) & 0x3F ] +
279
+ '=='
280
+ )
247
281
} else if ( extraBytes === 2 ) {
248
- tmp = ( uint8 [ len - 2 ] << 8 ) + ( uint8 [ len - 1 ] )
249
- output += lookup [ tmp >> 10 ]
250
- output += lookup [ ( tmp >> 4 ) & 0x3F ]
251
- output += lookup [ ( tmp << 2 ) & 0x3F ]
252
- output += '='
282
+ tmp = ( uint8 [ len - 2 ] << 8 ) + uint8 [ len - 1 ]
283
+ parts . push (
284
+ lookup [ tmp >> 10 ] +
285
+ lookup [ ( tmp >> 4 ) & 0x3F ] +
286
+ lookup [ ( tmp << 2 ) & 0x3F ] +
287
+ '='
288
+ )
253
289
}
254
290
255
- parts . push ( output )
256
-
257
291
return parts . join ( '' )
258
292
}
259
293
0 commit comments