source: trip-planner-front/node_modules/@webassemblyjs/helper-buffer/lib/index.js@ 571e0df

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

initial commit

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