This commit is contained in:
AJ ONeal 2017-09-25 12:00:04 -06:00
parent af6f9b37eb
commit be4cfac1af
3 changed files with 49 additions and 3 deletions

24
bin/cli.js Normal file
View File

@ -0,0 +1,24 @@
(function () {
'use strict';
var hexdump = require('../').hexdump;
var fsname = process.argv[2];
var fs = require('fs');
if (!fsname || '--help' === fs || '-h' === fs) {
console.error('Usage: hexdump.js <filepath>');
return;
}
try {
fs.statSync(fsname);
} catch(e) {
console.error(e.message);
return;
}
var nb = fs.readFileSync(fsname);
var str = hexdump(nb.buffer, nb.byteOffset, nb.byteLength);
console.log(str);
}());

View File

@ -1,8 +1,8 @@
(function (exports) {
'use strict';
exports.hexdump = function hexdump(ab) {
var ui8 = new Uint8Array(ab);
exports.hexdump = function hexdump(ab, offset, len) {
var ui8 = new Uint8Array(ab.buffer || ab, offset || ab.byteOffset, len || ab.byteLength);
var bytecount = 0;
var head = ' 0 1 2 3 4 5 6 7 8 9 A B C D E F';
var trail;
@ -22,7 +22,8 @@ exports.hexdump = function hexdump(ab) {
return lead + ' ' + str;
}).join('\n');
trail = ab.byteLength.toString(16);
trail = (len || ab.byteLength).toString(16);
while (trail.length < 7) {
trail = '0' + trail;
}

21
package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "hexdump",
"version": "1.0.0",
"description": "Like hexdump on *nix, but in JavaScript.",
"main": "hexdump.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@git.daplie.com:Daplie/hexdump.js.git"
},
"keywords": [
"hexdump",
"binary",
"bin",
"js"
],
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)",
"license": "MIT"
}