UNPKG

2.77 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.writeUInt32LE = exports.readUInt32LE = exports.writeUInt32BE = exports.readUInt32BE = exports.writeUInt16LE = exports.readUInt16LE = exports.writeUInt8 = exports.readUInt8 = exports.writeUInt16BE = exports.readUInt16BE = exports.alloc = exports.equals = void 0;
4function equals(a, b) {
5 if (a.byteLength !== b.byteLength)
6 return false;
7 for (let i = 0; i < a.byteLength; i++) {
8 if (a[i] !== b[i])
9 return false;
10 }
11 return true;
12}
13exports.equals = equals;
14function alloc(length, value) {
15 const a = new Uint8Array(length);
16 for (let i = 0; i < length; i++) {
17 a[i] = value;
18 }
19 return a;
20}
21exports.alloc = alloc;
22function readUInt16BE(source, offset) {
23 return ((source[offset + 0] << 8) | source[offset + 1]) >>> 0;
24}
25exports.readUInt16BE = readUInt16BE;
26function writeUInt16BE(source, value, offset) {
27 source[offset + 0] = value >>> 8;
28 source[offset + 1] = value >>> 0;
29}
30exports.writeUInt16BE = writeUInt16BE;
31function readUInt8(source, offset) {
32 return source[offset];
33}
34exports.readUInt8 = readUInt8;
35function writeUInt8(destination, value, offset) {
36 destination[offset] = value;
37}
38exports.writeUInt8 = writeUInt8;
39function readUInt16LE(source, offset) {
40 return ((source[offset + 0] << 0) >>> 0) | ((source[offset + 1] << 8) >>> 0);
41}
42exports.readUInt16LE = readUInt16LE;
43function writeUInt16LE(destination, value, offset) {
44 destination[offset + 0] = value & 255;
45 value >>>= 8;
46 destination[offset + 1] = value & 255;
47}
48exports.writeUInt16LE = writeUInt16LE;
49function readUInt32BE(source, offset) {
50 return (source[offset] * 2 ** 24 +
51 source[offset + 1] * 2 ** 16 +
52 source[offset + 2] * 2 ** 8 +
53 source[offset + 3]);
54}
55exports.readUInt32BE = readUInt32BE;
56function writeUInt32BE(destination, value, offset) {
57 destination[offset + 3] = value;
58 value >>>= 8;
59 destination[offset + 2] = value;
60 value >>>= 8;
61 destination[offset + 1] = value;
62 value >>>= 8;
63 destination[offset] = value;
64}
65exports.writeUInt32BE = writeUInt32BE;
66function readUInt32LE(source, offset) {
67 return (((source[offset + 0] << 0) >>> 0) |
68 ((source[offset + 1] << 8) >>> 0) |
69 ((source[offset + 2] << 16) >>> 0) |
70 ((source[offset + 3] << 24) >>> 0));
71}
72exports.readUInt32LE = readUInt32LE;
73function writeUInt32LE(destination, value, offset) {
74 destination[offset + 0] = value & 255;
75 value >>>= 8;
76 destination[offset + 1] = value & 255;
77 value >>>= 8;
78 destination[offset + 2] = value & 255;
79 value >>>= 8;
80 destination[offset + 3] = value & 255;
81}
82exports.writeUInt32LE = writeUInt32LE;
83//# sourceMappingURL=buffer.js.map
\No newline at end of file