const MASK=0xffffffff; function bytes2int32(arr){ return arr.reduce((acc,b,i)=>acc|b<<(i*8)); } function bytes2int32s(arr){ let res=[]; for(let i=0;i>>=8; } return res; } function int32s2bytes(arr){ return arr.map(int322bytes).reduce((acc,bytes)=>acc.concat(bytes)); } function bytes2hex(arr){ return arr.map(x=>x.toString(16).padStart(2,"0")).join(""); } function str2utf8(s){ let res=[]; let c=s.codePointAt(0); for(let i=0; c!==undefined; i++,c=s.codePointAt(i)){ if(c<0x80){res.push(c);} else if(c<0x800){ res.push(0b11000000|(c>>>6)); res.push(0b10000000|(c&0b111111)); } else if(c<0x10000){ res.push(0b11100000|(c>>>12)); res.push(0b10000000|((c>>>6)&0b111111)); res.push(0b10000000|(c&0b111111)); } else{ res.push(0b11110000|(c>>>18)); res.push(0b10000000|((c>>>12)&0b111111)); res.push(0b10000000|((c>>>6)&0b111111)); res.push(0b10000000|(c&0b111111)); } if(c>0xffff){i++;} // skip surrogate } return res; } function utf82str(arr){ let res=[]; for(let i=0;iString.fromCodePoint(x)).join(""); } if(typeof module!=='undefined'&&module.hasOwnProperty('exports')){ module.exports.bytes2int32=bytes2int32; module.exports.bytes2int32s=bytes2int32s; module.exports.int322bytes=int322bytes; module.exports.int32s2bytes=int32s2bytes; module.exports.bytes2hex=bytes2hex; module.exports.str2utf8=str2utf8; module.exports.utf82str=utf82str; }