@@ -14,13 +14,13 @@ if(typeof Buffer !== 'undefined') {
14
14
15
15
function new_raw_buf ( len /*:number*/ ) {
16
16
/* jshint -W056 */
17
- return has_buf ? Buffer . alloc ( len ) : new Array ( len ) ;
17
+ return has_buf ? Buffer . alloc ( len ) : typeof Uint8Array != "undefined" ? new Uint8Array ( len ) : new Array ( len ) ;
18
18
/* jshint +W056 */
19
19
}
20
20
21
21
function new_unsafe_buf ( len /*:number*/ ) {
22
22
/* jshint -W056 */
23
- return has_buf ? Buffer . allocUnsafe ( len ) : new Array ( len ) ;
23
+ return has_buf ? Buffer . allocUnsafe ( len ) : typeof Uint8Array != "undefined" ? new Uint8Array ( len ) : new Array ( len ) ;
24
24
/* jshint +W056 */
25
25
}
26
26
@@ -55,6 +55,52 @@ function ab2a(data/*:ArrayBuffer|Uint8Array*/)/*:Array<number>*/ {
55
55
return o ;
56
56
}
57
57
58
- var bconcat = function ( bufs ) { return [ ] . concat . apply ( [ ] , bufs ) ; } ;
58
+ function utf8decode ( content /*:string*/ ) {
59
+ var out = [ ] , widx = 0 ;
60
+ var o = new_raw_buf ( content . length + 255 ) ;
61
+ for ( var ridx = 0 ; ridx < content . length ; ++ ridx ) {
62
+ var c = content . charCodeAt ( ridx ) ;
63
+ if ( c < 0x80 ) o [ widx ++ ] = c ;
64
+ else if ( c < 0x800 ) {
65
+ o [ widx ++ ] = ( 192 | ( ( c >> 6 ) & 31 ) ) ;
66
+ o [ widx ++ ] = ( 128 | ( c & 63 ) ) ;
67
+ } else if ( c >= 0xD800 && c < 0xE000 ) {
68
+ c = ( c & 1023 ) + 64 ;
69
+ var d = str . charCodeAt ( ++ ridx ) & 1023 ;
70
+ o [ widx ++ ] = ( 240 | ( ( c >> 8 ) & 7 ) ) ;
71
+ o [ widx ++ ] = ( 128 | ( ( c >> 2 ) & 63 ) ) ;
72
+ o [ widx ++ ] = ( 128 | ( ( d >> 6 ) & 15 ) | ( ( c & 3 ) << 4 ) ) ;
73
+ o [ widx ++ ] = ( 128 | ( d & 63 ) ) ;
74
+ } else {
75
+ o [ widx ++ ] = ( 224 | ( ( c >> 12 ) & 15 ) ) ;
76
+ o [ widx ++ ] = ( 128 | ( ( c >> 6 ) & 63 ) ) ;
77
+ o [ widx ++ ] = ( 128 | ( c & 63 ) ) ;
78
+ }
79
+ if ( widx > 65530 ) {
80
+ out . push ( o . slice ( 0 , widx ) ) ;
81
+ widx = 0 ;
82
+ o = new_raw_buf ( 65535 ) ;
83
+ }
84
+ }
85
+ out . push ( o . slice ( 0 , widx ) ) ;
86
+ return bconcat ( out ) ;
87
+ }
88
+
89
+ var bconcat = function ( bufs ) {
90
+ if ( typeof Uint8Array !== "undefined" ) {
91
+ var i = 0 , maxlen = 0 ;
92
+ for ( i = 0 ; i < bufs . length ; ++ i ) maxlen += bufs [ i ] . length ;
93
+ var o = new Uint8Array ( maxlen ) ;
94
+ var len = 0 ;
95
+ for ( i = 0 , maxlen = 0 ; i < bufs . length ; maxlen += len , ++ i ) {
96
+ len = bufs [ i ] . length ;
97
+ if ( bufs [ i ] instanceof Uint8Array ) o . set ( bufs [ i ] , maxlen ) ;
98
+ else if ( typeof bufs [ i ] == "string" ) { throw "wtf" ; }
99
+ else o . set ( new Uint8Array ( bufs [ i ] ) , maxlen ) ;
100
+ }
101
+ return o ;
102
+ }
103
+ return [ ] . concat . apply ( [ ] , bufs . map ( function ( buf ) { return Array . isArray ( buf ) ? buf : [ ] . slice . call ( buf ) ; } ) ) ;
104
+ } ;
59
105
60
106
var chr0 = / \u0000 / g, chr1 = / [ \u0001 - \u0006 ] / g;
0 commit comments