-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
28 lines (21 loc) · 765 Bytes
/
utils.js
File metadata and controls
28 lines (21 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Deferred {
constructor() {
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
}
}
function unsignedIntFromBytes(byteOrBytes) {
const bytesCombined = Array.isArray(byteOrBytes) ? byteOrBytes.join("") : byteOrBytes;
const integerValue = parseInt(bytesCombined, 16);
return integerValue;
}
function signedIntFromBytes(byteOrBytes) {
const unsignedIntegerValue = unsignedIntFromBytes(byteOrBytes);
const numberOfBytes = Array.isArray(byteOrBytes) ? byteOrBytes.length : 1;
const numberOfValuesPerBytes = 2 ** (8 * numberOfBytes);
return unsignedIntegerValue < numberOfValuesPerBytes / 2
? unsignedIntegerValue
: unsignedIntegerValue - numberOfValuesPerBytes;
}