-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathImmutable.js
More file actions
45 lines (26 loc) · 1.43 KB
/
Immutable.js
File metadata and controls
45 lines (26 loc) · 1.43 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Buffer } from "node:buffer";
import { inspect } from "util";
export const showImpl = inspect;
export const eqImpl = (a, b) => a.equals(b);
export const compareImpl = (a, b) => a.compare(b);
export const comparePartsImpl = (src, target, targetStart, targetEnd, sourceStart, sourceEnd) =>
src.compare(target, targetStart, targetEnd, sourceStart, sourceEnd);
export const alloc = (size) => Buffer.alloc(size);
export const fromArray = (octets) => Buffer.from(octets);
export const size = (buff) => buff.length;
export function toArray(buff) {
var json = buff.toJSON();
return json.data || json;
}
export const toArrayBuffer = (buff) =>
buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength);
export const fromArrayBuffer = (ab) => Buffer.from(ab);
export const fromStringImpl = (str, encoding) => Buffer.from(str, encoding);
export const readImpl = (ty, offset, buf) => buf["read" + ty](offset);
export const readStringImpl = (enc, start, end, buff) => buff.toString(enc, start, end);
export const getAtOffsetImpl = (offset, buff) => buff[offset];
export const toStringImpl = (enc, buff) => buff.toString(enc);
export const toStringSubImpl = (enc, start, end, buff) => buff.toString(enc, start, end);
export const sliceImpl = (start, end, buff) => buff.slice(start, end);
export const concat = (buffs) => Buffer.concat(buffs);
export const concatToLength = (buffs, totalLength) => Buffer.concat(buffs, totalLength);