@webassemblyjs/helper-buffer
Advanced tools
Comparing version 1.2.7 to 1.2.8
@@ -17,8 +17,8 @@ "use strict"; | ||
var oldConsoleLog = console.log; | ||
function compareArrayBuffers(l, r) { | ||
var oldConsoleLog = console.log; | ||
/** | ||
* Decode left | ||
*/ | ||
var bufferL = ""; | ||
@@ -34,5 +34,11 @@ | ||
decode(l, { | ||
dump: true | ||
}); | ||
try { | ||
decode(l, { | ||
dump: true | ||
}); | ||
} catch (e) { | ||
console.error(bufferL); | ||
console.error(e); | ||
throw e; | ||
} | ||
/** | ||
@@ -42,2 +48,3 @@ * Decode right | ||
var bufferR = ""; | ||
@@ -53,5 +60,12 @@ | ||
decode(r, { | ||
dump: true | ||
}); | ||
try { | ||
decode(r, { | ||
dump: true | ||
}); | ||
} catch (e) { | ||
console.error(bufferR); | ||
console.error(e); | ||
throw e; | ||
} | ||
console.log = oldConsoleLog; | ||
@@ -58,0 +72,0 @@ var out = diff(bufferL, bufferR); |
@@ -8,3 +8,8 @@ "use strict"; | ||
exports.makeBuffer = makeBuffer; | ||
exports.fromHexdump = fromHexdump; | ||
function _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); } } | ||
var debug = require("debug")("wasm"); | ||
function concatUint8Arrays() { | ||
@@ -37,3 +42,7 @@ for (var _len = arguments.length, arrays = new Array(_len), _key = 0; _key < _len; _key++) { | ||
var beforeBytes = buffer.slice(0, startLoc); | ||
var afterBytes = buffer.slice(endLoc, buffer.length); // replacement is empty, we can omit it | ||
var afterBytes = buffer.slice(endLoc, buffer.length); | ||
debug("overrideBytesInBuffer start=%d end=%d newBytes=%s", startLoc, endLoc, // $FlowIgnore | ||
newBytes.map(function (dec) { | ||
return dec.toString("16"); | ||
}).join()); // replacement is empty, we can omit it | ||
@@ -55,2 +64,24 @@ if (newBytes.length === 0) { | ||
return new Uint8Array(bytes).buffer; | ||
} | ||
function fromHexdump(str) { | ||
var lines = str.split("\n"); // remove any leading left whitespace | ||
lines = lines.map(function (line) { | ||
return line.trim(); | ||
}); | ||
var bytes = lines.reduce(function (acc, line) { | ||
var cols = line.split(" "); // remove the offset, left column | ||
cols.shift(); | ||
cols = cols.filter(function (x) { | ||
return x !== ""; | ||
}); | ||
var bytes = cols.map(function (x) { | ||
return parseInt(x, 16); | ||
}); | ||
acc.push.apply(acc, _toConsumableArray(bytes)); | ||
return acc; | ||
}, []); | ||
return Buffer.from(bytes); | ||
} |
{ | ||
"name": "@webassemblyjs/helper-buffer", | ||
"version": "1.2.7", | ||
"version": "1.2.8", | ||
"description": "Buffer manipulation utility", | ||
@@ -19,5 +19,5 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@webassemblyjs/wasm-parser": "1.2.7", | ||
"@webassemblyjs/wasm-parser": "1.2.8", | ||
"jest-diff": "^22.4.0" | ||
} | ||
} |
@@ -6,5 +6,5 @@ // this are dev dependencies | ||
const oldConsoleLog = console.log; | ||
export function compareArrayBuffers(l, r) { | ||
const oldConsoleLog = console.log; | ||
/** | ||
@@ -16,4 +16,11 @@ * Decode left | ||
console.log = (...texts) => (bufferL += texts.join("") + "\n"); | ||
decode(l, { dump: true }); | ||
try { | ||
decode(l, { dump: true }); | ||
} catch (e) { | ||
console.error(bufferL); | ||
console.error(e); | ||
throw e; | ||
} | ||
/** | ||
@@ -25,4 +32,11 @@ * Decode right | ||
console.log = (...texts) => (bufferR += texts.join("") + "\n"); | ||
decode(r, { dump: true }); | ||
try { | ||
decode(r, { dump: true }); | ||
} catch (e) { | ||
console.error(bufferR); | ||
console.error(e); | ||
throw e; | ||
} | ||
console.log = oldConsoleLog; | ||
@@ -29,0 +43,0 @@ |
// @flow | ||
const debug = require("debug")("wasm"); | ||
function concatUint8Arrays(...arrays: Array<Uint8Array>) { | ||
@@ -29,2 +31,10 @@ const totalLength = arrays.reduce((a, b) => a + b.length, 0); | ||
debug( | ||
"overrideBytesInBuffer start=%d end=%d newBytes=%s", | ||
startLoc, | ||
endLoc, | ||
// $FlowIgnore | ||
newBytes.map(dec => dec.toString("16")).join() | ||
); | ||
// replacement is empty, we can omit it | ||
@@ -44,1 +54,25 @@ if (newBytes.length === 0) { | ||
} | ||
export function fromHexdump(str: string): Buffer { | ||
let lines = str.split("\n"); | ||
// remove any leading left whitespace | ||
lines = lines.map(line => line.trim()); | ||
const bytes = lines.reduce((acc, line) => { | ||
let cols = line.split(" "); | ||
// remove the offset, left column | ||
cols.shift(); | ||
cols = cols.filter(x => x !== ""); | ||
const bytes = cols.map(x => parseInt(x, 16)); | ||
acc.push(...bytes); | ||
return acc; | ||
}, []); | ||
return Buffer.from(bytes); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7057
214