2017-09-25 18:26:15 +00:00
|
|
|
#!/usr/bin/env node
|
2017-09-25 18:00:04 +00:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var hexdump = require('../').hexdump;
|
|
|
|
var fsname = process.argv[2];
|
|
|
|
var fs = require('fs');
|
2017-10-07 02:30:21 +00:00
|
|
|
var opts = {};
|
2017-09-25 18:00:04 +00:00
|
|
|
|
2017-10-07 02:30:21 +00:00
|
|
|
if (!fsname || '--help' === fsname || '-h' === fsname) {
|
|
|
|
console.error('Usage: hexdump.js -C <filepath>');
|
2017-09-25 18:22:44 +00:00
|
|
|
process.exit(2);
|
2017-09-25 18:00:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-07 02:30:21 +00:00
|
|
|
if ('-C' === fsname) {
|
|
|
|
opts.C = true;
|
|
|
|
fsname = process.argv[3];
|
|
|
|
}
|
|
|
|
|
2017-09-25 18:00:04 +00:00
|
|
|
try {
|
|
|
|
fs.statSync(fsname);
|
|
|
|
} catch(e) {
|
|
|
|
console.error(e.message);
|
2017-09-25 18:22:44 +00:00
|
|
|
process.exit(3);
|
2017-09-25 18:00:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var nb = fs.readFileSync(fsname);
|
2017-10-07 02:30:21 +00:00
|
|
|
var str = hexdump(nb.buffer, nb.byteOffset, nb.byteLength, opts);
|
2017-09-25 18:00:04 +00:00
|
|
|
console.log(str);
|
|
|
|
|
|
|
|
}());
|