[79a0317] | 1 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
---|
| 2 |
|
---|
| 3 | function _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."); }
|
---|
| 4 |
|
---|
| 5 | function _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); }
|
---|
| 6 |
|
---|
| 7 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
---|
| 8 |
|
---|
| 9 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
---|
| 10 |
|
---|
| 11 | function _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; }
|
---|
| 12 |
|
---|
| 13 | function concatUint8Arrays() {
|
---|
| 14 | for (var _len = arguments.length, arrays = new Array(_len), _key = 0; _key < _len; _key++) {
|
---|
| 15 | arrays[_key] = arguments[_key];
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | var totalLength = arrays.reduce(function (a, b) {
|
---|
| 19 | return a + b.length;
|
---|
| 20 | }, 0);
|
---|
| 21 | var result = new Uint8Array(totalLength);
|
---|
| 22 | var offset = 0;
|
---|
| 23 |
|
---|
| 24 | for (var _i = 0, _arrays = arrays; _i < _arrays.length; _i++) {
|
---|
| 25 | var arr = _arrays[_i];
|
---|
| 26 |
|
---|
| 27 | if (arr instanceof Uint8Array === false) {
|
---|
| 28 | throw new Error("arr must be of type Uint8Array");
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | result.set(arr, offset);
|
---|
| 32 | offset += arr.length;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | return result;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | export function overrideBytesInBuffer(buffer, startLoc, endLoc, newBytes) {
|
---|
| 39 | var beforeBytes = buffer.slice(0, startLoc);
|
---|
| 40 | var afterBytes = buffer.slice(endLoc, buffer.length); // replacement is empty, we can omit it
|
---|
| 41 |
|
---|
| 42 | if (newBytes.length === 0) {
|
---|
| 43 | return concatUint8Arrays(beforeBytes, afterBytes);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | var replacement = Uint8Array.from(newBytes);
|
---|
| 47 | return concatUint8Arrays(beforeBytes, replacement, afterBytes);
|
---|
| 48 | }
|
---|
| 49 | export function makeBuffer() {
|
---|
| 50 | for (var _len2 = arguments.length, splitedBytes = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
---|
| 51 | splitedBytes[_key2] = arguments[_key2];
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | // $FlowIgnore
|
---|
| 55 | var bytes = [].concat.apply([], splitedBytes);
|
---|
| 56 | return new Uint8Array(bytes).buffer;
|
---|
| 57 | }
|
---|
| 58 | export function 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 new Uint8Array(bytes);
|
---|
| 78 | } |
---|