hexdump.js/bin/cli.js

31 lines
560 B
JavaScript
Raw Normal View History

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