source: imaps-frontend/node_modules/@webassemblyjs/helper-buffer/lib/index.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 3.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) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
12function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
14function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
16function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
18function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
20function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
21
22function concatUint8Arrays() {
23 for (var _len = arguments.length, arrays = new Array(_len), _key = 0; _key < _len; _key++) {
24 arrays[_key] = arguments[_key];
25 }
26
27 var totalLength = arrays.reduce(function (a, b) {
28 return a + b.length;
29 }, 0);
30 var result = new Uint8Array(totalLength);
31 var offset = 0;
32
33 for (var _i = 0, _arrays = arrays; _i < _arrays.length; _i++) {
34 var arr = _arrays[_i];
35
36 if (arr instanceof Uint8Array === false) {
37 throw new Error("arr must be of type Uint8Array");
38 }
39
40 result.set(arr, offset);
41 offset += arr.length;
42 }
43
44 return result;
45}
46
47function overrideBytesInBuffer(buffer, startLoc, endLoc, newBytes) {
48 var beforeBytes = buffer.slice(0, startLoc);
49 var afterBytes = buffer.slice(endLoc, buffer.length); // replacement is empty, we can omit it
50
51 if (newBytes.length === 0) {
52 return concatUint8Arrays(beforeBytes, afterBytes);
53 }
54
55 var replacement = Uint8Array.from(newBytes);
56 return concatUint8Arrays(beforeBytes, replacement, afterBytes);
57}
58
59function makeBuffer() {
60 for (var _len2 = arguments.length, splitedBytes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
61 splitedBytes[_key2] = arguments[_key2];
62 }
63
64 // $FlowIgnore
65 var bytes = [].concat.apply([], splitedBytes);
66 return new Uint8Array(bytes).buffer;
67}
68
69function fromHexdump(str) {
70 var lines = str.split("\n"); // remove any leading left whitespace
71
72 lines = lines.map(function (line) {
73 return line.trim();
74 });
75 var bytes = lines.reduce(function (acc, line) {
76 var cols = line.split(" "); // remove the offset, left column
77
78 cols.shift();
79 cols = cols.filter(function (x) {
80 return x !== "";
81 });
82 var bytes = cols.map(function (x) {
83 return parseInt(x, 16);
84 });
85 acc.push.apply(acc, _toConsumableArray(bytes));
86 return acc;
87 }, []);
88 return new Uint8Array(bytes);
89}
Note: See TracBrowser for help on using the repository browser.