js-cfb/bin/cfb

33 lines
944 B
Plaintext
Raw Normal View History

2013-09-05 18:55:36 +00:00
#!/usr/bin/env node
var CFB = require('../cfb');
var fs = require('fs'), program = require('commander');
program
2013-11-29 07:09:46 +00:00
.version('0.8.1')
.usage('[options] <file>')
.option('-q, --quiet', 'print but do not extract')
.parse(process.argv);
2013-09-05 18:55:36 +00:00
if(program.args.length === 0 || !fs.existsSync(program.args[0])) {
console.error("Usage: " + process.argv[1] + " [-q] <cfb_file>");
process.exit(1);
2013-09-05 18:55:36 +00:00
}
var cfb = CFB.read(program.args[0], {type:'file'});
if(program.quiet) {
console.log("Full Paths:")
console.log(cfb.FullPaths.map(function(x) { return " " + x; }).join("\n"));
console.log("Full Path Directory:")
console.log(cfb.FullPathDir);
return;
2013-09-05 18:55:36 +00:00
}
for(var i=0; i != cfb.FullPaths.length; ++i) {
if(cfb.FullPaths[i].slice(-1) === "/") {
console.error("mkdir " + cfb.FullPaths[i]);
fs.mkdirSync(cfb.FullPaths[i]);
2013-09-05 18:55:36 +00:00
} else {
console.error("writing " + cfb.FullPaths[i]);
fs.writeFileSync(cfb.FullPaths[i], cfb.FileIndex[i].content);
2013-09-05 18:55:36 +00:00
}
}