Comparing version 1.0.4 to 1.0.5
@@ -8,5 +8,6 @@ #!/usr/bin/env node | ||
var fs = require('fs'); | ||
var opts = {}; | ||
if (!fsname || '--help' === fs || '-h' === fs) { | ||
console.error('Usage: hexdump.js <filepath>'); | ||
if (!fsname || '--help' === fsname || '-h' === fsname) { | ||
console.error('Usage: hexdump.js -C <filepath>'); | ||
process.exit(2); | ||
@@ -16,2 +17,7 @@ return; | ||
if ('-C' === fsname) { | ||
opts.C = true; | ||
fsname = process.argv[3]; | ||
} | ||
try { | ||
@@ -26,5 +32,5 @@ fs.statSync(fsname); | ||
var nb = fs.readFileSync(fsname); | ||
var str = hexdump(nb.buffer, nb.byteOffset, nb.byteLength); | ||
var str = hexdump(nb.buffer, nb.byteOffset, nb.byteLength, opts); | ||
console.log(str); | ||
}()); |
(function (exports) { | ||
'use strict'; | ||
exports.hexdump = function hexdump(ab, offset, len) { | ||
exports.hexdump = function hexdump(ab, offset, len, opts) { | ||
if (!opts) { opts = {}; } | ||
var ui8 = new Uint8Array(ab.buffer || ab, offset || ab.byteOffset, len || ab.byteLength); | ||
@@ -23,3 +24,17 @@ var bytecount = 0; | ||
return lead + ' ' + str; | ||
while (str.length < 48) { | ||
str += ' '; | ||
} | ||
if (opts.C) { | ||
return lead + ' ' + str + ' |' + str.replace(/ /g, '').match(/.{1,2}/g).map(function (ch) { | ||
var c = String.fromCharCode(parseInt(ch, 16)); | ||
if (!/[ -~]/.test(c)) { | ||
c = '.'; | ||
} | ||
return c; | ||
}).join('') + '|'; | ||
} else { | ||
return lead + ' ' + str; | ||
} | ||
}).join('\n'); | ||
@@ -26,0 +41,0 @@ |
{ | ||
"name": "hexdump.js", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Like hexdump on *nix, but in JavaScript.", | ||
@@ -14,3 +14,3 @@ "main": "hexdump.js", | ||
"type": "git", | ||
"url": "git@git.daplie.com:Daplie/hexdump.js.git" | ||
"url": "https://git.coolaj86.com/coolaj86/hexdump.js.git" | ||
}, | ||
@@ -17,0 +17,0 @@ "keywords": [ |
@@ -48,6 +48,6 @@ hexdump.js | ||
# As a library | ||
npm install --save 'git+https://git.daplie.com/Daplie/hexdump.js.git' | ||
npm install --save 'git+https://git.coolaj86.com/coolaj86/hexdump.js.git' | ||
# As a global CLI (useful on windows) | ||
npm install --global 'git+https://git.daplie.com/Daplie/hexdump.js.git' | ||
npm install --global 'git+https://git.coolaj86.com/coolaj86/hexdump.js.git' | ||
``` | ||
@@ -64,1 +64,8 @@ | ||
``` | ||
API | ||
--- | ||
``` | ||
hexdump(arrayBuffer, byteOffset, byteLength); | ||
``` |
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
3590
69
70