source: trip-planner-front/node_modules/@webassemblyjs/helper-buffer/esm/index.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
2
3function concatUint8Arrays() {
4 for (var _len = arguments.length, arrays = new Array(_len), _key = 0; _key < _len; _key++) {
5 arrays[_key] = arguments[_key];
6 }
7
8 var totalLength = arrays.reduce(function (a, b) {
9 return a + b.length;
10 }, 0);
11 var result = new Uint8Array(totalLength);
12 var offset = 0;
13
14 for (var _i = 0; _i < arrays.length; _i++) {
15 var arr = arrays[_i];
16
17 if (arr instanceof Uint8Array === false) {
18 throw new Error("arr must be of type Uint8Array");
19 }
20
21 result.set(arr, offset);
22 offset += arr.length;
23 }
24
25 return result;
26}
27
28export function overrideBytesInBuffer(buffer, startLoc, endLoc, newBytes) {
29 var beforeBytes = buffer.slice(0, startLoc);
30 var afterBytes = buffer.slice(endLoc, buffer.length); // replacement is empty, we can omit it
31
32 if (newBytes.length === 0) {
33 return concatUint8Arrays(beforeBytes, afterBytes);
34 }
35
36 var replacement = Uint8Array.from(newBytes);
37 return concatUint8Arrays(beforeBytes, replacement, afterBytes);
38}
39export function makeBuffer() {
40 for (var _len2 = arguments.length, splitedBytes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
41 splitedBytes[_key2] = arguments[_key2];
42 }
43
44 var bytes = [].concat.apply([], splitedBytes);
45 return new Uint8Array(bytes).buffer;
46}
47export function fromHexdump(str) {
48 var lines = str.split("\n"); // remove any leading left whitespace
49
50 lines = lines.map(function (line) {
51 return line.trim();
52 });
53 var bytes = lines.reduce(function (acc, line) {
54 var cols = line.split(" "); // remove the offset, left column
55
56 cols.shift();
57 cols = cols.filter(function (x) {
58 return x !== "";
59 });
60 var bytes = cols.map(function (x) {
61 return parseInt(x, 16);
62 });
63 acc.push.apply(acc, _toConsumableArray(bytes));
64 return acc;
65 }, []);
66 return Buffer.from(bytes);
67}
Note: See TracBrowser for help on using the repository browser.