2017-09-14 21:14:22 +00:00
|
|
|
var has_buf = (typeof Buffer !== 'undefined' && typeof process !== 'undefined' && typeof process.versions !== 'undefined' && process.versions.node);
|
|
|
|
|
2018-07-08 08:08:15 +00:00
|
|
|
var Buffer_from = /*::(*/function(){}/*:: :any)*/;
|
|
|
|
|
2018-04-28 17:52:41 +00:00
|
|
|
if(typeof Buffer !== 'undefined') {
|
2018-07-08 08:08:15 +00:00
|
|
|
var nbfs = !Buffer.from;
|
|
|
|
if(!nbfs) try { Buffer.from("foo", "utf8"); } catch(e) { nbfs = true; }
|
2018-09-04 07:14:20 +00:00
|
|
|
Buffer_from = /*::((*/nbfs ? function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); } : Buffer.from.bind(Buffer)/*::) :any)*/;
|
2018-04-28 17:52:41 +00:00
|
|
|
// $FlowIgnore
|
2021-09-05 17:24:57 +00:00
|
|
|
if(!Buffer.alloc) Buffer.alloc = function(n) { var b = new Buffer(n); b.fill(0); return b; };
|
2018-09-04 07:14:20 +00:00
|
|
|
// $FlowIgnore
|
|
|
|
if(!Buffer.allocUnsafe) Buffer.allocUnsafe = function(n) { return new Buffer(n); };
|
2018-04-28 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 21:14:22 +00:00
|
|
|
function new_raw_buf(len/*:number*/) {
|
|
|
|
/* jshint -W056 */
|
2018-04-28 17:52:41 +00:00
|
|
|
return has_buf ? Buffer.alloc(len) : new Array(len);
|
2017-09-14 21:14:22 +00:00
|
|
|
/* jshint +W056 */
|
|
|
|
}
|
|
|
|
|
2018-09-04 07:14:20 +00:00
|
|
|
function new_unsafe_buf(len/*:number*/) {
|
|
|
|
/* jshint -W056 */
|
|
|
|
return has_buf ? Buffer.allocUnsafe(len) : new Array(len);
|
|
|
|
/* jshint +W056 */
|
|
|
|
}
|
|
|
|
|
2020-07-09 06:12:05 +00:00
|
|
|
var s2a = function s2a(s/*:string*/)/*:RawBytes*/ {
|
2018-09-04 07:14:20 +00:00
|
|
|
if(has_buf) return Buffer_from(s, "binary");
|
2018-07-08 08:08:15 +00:00
|
|
|
return s.split("").map(function(x/*:string*/)/*:number*/{ return x.charCodeAt(0) & 0xff; });
|
2017-09-14 21:14:22 +00:00
|
|
|
};
|
|
|
|
|
2017-11-27 05:41:39 +00:00
|
|
|
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;
|