hexdump.js/bin/cli.js

28 lines
494 B
JavaScript
Raw Normal View History

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');
if (!fsname || '--help' === fs || '-h' === fs) {
console.error('Usage: hexdump.js <filepath>');
2017-09-25 18:22:44 +00:00
process.exit(2);
2017-09-25 18:00:04 +00:00
return;
}
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);
var str = hexdump(nb.buffer, nb.byteOffset, nb.byteLength);
console.log(str);
}());