|
1 |
| -var has_buf = (typeof Buffer !== 'undefined' && typeof process !== 'undefined' && typeof process.versions !== 'undefined' && !!process.versions.node); |
| 1 | +var has_buf = /*#__PURE__*/(function() { return typeof Buffer !== 'undefined' && typeof process !== 'undefined' && typeof process.versions !== 'undefined' && !!process.versions.node; })(); |
2 | 2 |
|
3 |
| -var Buffer_from = /*::(*/function(){}/*:: :any)*/; |
| 3 | +var Buffer_from = /*#__PURE__*/(function() { |
| 4 | + if(typeof Buffer !== 'undefined') { |
| 5 | + var nbfs = !Buffer.from; |
| 6 | + if(!nbfs) try { Buffer.from("foo", "utf8"); } catch(e) { nbfs = true; } |
| 7 | + return nbfs ? function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); } : Buffer.from.bind(Buffer); |
| 8 | + } |
| 9 | + return function() {}; |
| 10 | +})(); |
4 | 11 |
|
5 |
| -if(typeof Buffer !== 'undefined') { |
6 |
| - var nbfs = !Buffer.from; |
7 |
| - if(!nbfs) try { Buffer.from("foo", "utf8"); } catch(e) { nbfs = true; } |
8 |
| - Buffer_from = nbfs ? function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); } : Buffer.from.bind(Buffer); |
9 |
| - // $FlowIgnore |
10 |
| - if(!Buffer.alloc) Buffer.alloc = function(n) { return new Buffer(n); }; |
11 |
| - // $FlowIgnore |
12 |
| - if(!Buffer.allocUnsafe) Buffer.allocUnsafe = function(n) { return new Buffer(n); }; |
13 |
| -} |
14 | 12 |
|
15 | 13 | function new_raw_buf(len/*:number*/) {
|
16 | 14 | /* jshint -W056 */
|
17 |
| - return has_buf ? Buffer.alloc(len) : typeof Uint8Array != "undefined" ? new Uint8Array(len) : new Array(len); |
| 15 | + if(has_buf) return Buffer.alloc ? Buffer.alloc(len) : new Buffer(len); |
| 16 | + return typeof Uint8Array != "undefined" ? new Uint8Array(len) : new Array(len); |
18 | 17 | /* jshint +W056 */
|
19 | 18 | }
|
20 | 19 |
|
21 | 20 | function new_unsafe_buf(len/*:number*/) {
|
22 | 21 | /* jshint -W056 */
|
23 |
| - return has_buf ? Buffer.allocUnsafe(len) : typeof Uint8Array != "undefined" ? new Uint8Array(len) : new Array(len); |
| 22 | + if(has_buf) return Buffer.allocUnsafe ? Buffer.allocUnsafe(len) : new Buffer(len); |
| 23 | + return typeof Uint8Array != "undefined" ? new Uint8Array(len) : new Array(len); |
24 | 24 | /* jshint +W056 */
|
25 | 25 | }
|
26 | 26 |
|
@@ -55,6 +55,23 @@ function ab2a(data/*:ArrayBuffer|Uint8Array*/)/*:Array<number>*/ {
|
55 | 55 | return o;
|
56 | 56 | }
|
57 | 57 |
|
| 58 | +var bconcat = has_buf ? function(bufs) { return Buffer.concat(bufs.map(function(buf) { return Buffer.isBuffer(buf) ? buf : Buffer_from(buf); })); } : function(bufs) { |
| 59 | + if(typeof Uint8Array !== "undefined") { |
| 60 | + var i = 0, maxlen = 0; |
| 61 | + for(i = 0; i < bufs.length; ++i) maxlen += bufs[i].length; |
| 62 | + var o = new Uint8Array(maxlen); |
| 63 | + var len = 0; |
| 64 | + for(i = 0, maxlen = 0; i < bufs.length; maxlen += len, ++i) { |
| 65 | + len = bufs[i].length; |
| 66 | + if(bufs[i] instanceof Uint8Array) o.set(bufs[i], maxlen); |
| 67 | + else if(typeof bufs[i] == "string") { throw "wtf"; } |
| 68 | + else o.set(new Uint8Array(bufs[i]), maxlen); |
| 69 | + } |
| 70 | + return o; |
| 71 | + } |
| 72 | + return [].concat.apply([], bufs.map(function(buf) { return Array.isArray(buf) ? buf : [].slice.call(buf); })); |
| 73 | +}; |
| 74 | + |
58 | 75 | function utf8decode(content/*:string*/) {
|
59 | 76 | var out = [], widx = 0, L = content.length + 250;
|
60 | 77 | var o = new_raw_buf(content.length + 255);
|
@@ -87,21 +104,4 @@ function utf8decode(content/*:string*/) {
|
87 | 104 | return bconcat(out);
|
88 | 105 | }
|
89 | 106 |
|
90 |
| -var bconcat = function(bufs) { |
91 |
| - if(typeof Uint8Array !== "undefined") { |
92 |
| - var i = 0, maxlen = 0; |
93 |
| - for(i = 0; i < bufs.length; ++i) maxlen += bufs[i].length; |
94 |
| - var o = new Uint8Array(maxlen); |
95 |
| - var len = 0; |
96 |
| - for(i = 0, maxlen = 0; i < bufs.length; maxlen += len, ++i) { |
97 |
| - len = bufs[i].length; |
98 |
| - if(bufs[i] instanceof Uint8Array) o.set(bufs[i], maxlen); |
99 |
| - else if(typeof bufs[i] == "string") { throw "wtf"; } |
100 |
| - else o.set(new Uint8Array(bufs[i]), maxlen); |
101 |
| - } |
102 |
| - return o; |
103 |
| - } |
104 |
| - return [].concat.apply([], bufs.map(function(buf) { return Array.isArray(buf) ? buf : [].slice.call(buf); })); |
105 |
| -}; |
106 |
| - |
107 | 107 | var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;
|
0 commit comments