hexdump.js/bin/cli.js

31 lines
560 B
JavaScript
Raw Permalink Normal View History

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