2024-12-03 14:14:39 +08:00

2 lines
1.0 KiB
JavaScript

"use strict";const t=require("../common/vendor.js");exports.arrayToTimestamp=function(t){return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0},exports.convertWeekdaysToNumber=function(t){let e="00000000";for(const r of t){const t=r%7;e=e.substring(0,t)+"1"+e.substring(t+1)}return e=e.split("").reverse().join(""),parseInt(e,2)},exports.createPackageEnd=function(e,r){let n=new Uint8Array(e.length+r.length);n.set(e),n.set(r,e.length);const o=t.crc.crc16kermit(n);let s=new Uint8Array(n.length+2);return s.set(n),s.set([o/256,o%256],n.length),s},exports.md5Encrypt=function(e,r,n){const o=e.length+4+16,s=new Uint8Array(o);for(let t=0;t<e.length;t++)s[t]=e.charCodeAt(t);s.set(r,e.length),s.set(n,e.length+4);const c=t.md5Exports.md5(s);return new Uint8Array(c.match(/.{1,2}/g).map((t=>parseInt(t,16))))},exports.timestampToArray=function(t){const e=new Uint8Array(4);return e[0]=(4278190080&t)>>24,e[1]=(16711680&t)>>16,e[2]=(65280&t)>>8,e[3]=255&t,e},exports.uint8ArrayToString=function(t){let e="";for(let r=0;r<t.length;r++)0!==t[r]&&(e+=String.fromCharCode(t[r]));return e};