js-cfb/bits/05_buf.js

22 lines
751 B
JavaScript
Raw Normal View History

2017-09-14 21:14:22 +00:00
var has_buf = (typeof Buffer !== 'undefined' && typeof process !== 'undefined' && typeof process.versions !== 'undefined' && process.versions.node);
if(typeof Buffer !== 'undefined') {
// $FlowIgnore
if(!Buffer.from) Buffer.from = function(buf, enc) { return (enc) ? new Buffer(buf, enc) : new Buffer(buf); };
// $FlowIgnore
if(!Buffer.alloc) Buffer.alloc = function(n) { return new Buffer(n); };
}
2017-09-14 21:14:22 +00:00
function new_raw_buf(len/*:number*/) {
/* jshint -W056 */
return has_buf ? Buffer.alloc(len) : new Array(len);
2017-09-14 21:14:22 +00:00
/* jshint +W056 */
}
var s2a = function s2a(s/*:string*/) {
if(has_buf) return Buffer.from(s, "binary");
2017-09-14 21:14:22 +00:00
return s.split("").map(function(x){ return x.charCodeAt(0) & 0xff; });
};
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;