2013-09-05 18:55:36 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2014-05-20 17:43:03 +00:00
|
|
|
var CFB = require('../');
|
2013-11-13 23:36:47 +00:00
|
|
|
var fs = require('fs'), program = require('commander');
|
|
|
|
program
|
2014-05-20 17:43:03 +00:00
|
|
|
.version(CFB.version)
|
2013-11-13 23:36:47 +00:00
|
|
|
.usage('[options] <file>')
|
|
|
|
.option('-q, --quiet', 'print but do not extract')
|
|
|
|
.parse(process.argv);
|
2013-09-05 18:55:36 +00:00
|
|
|
|
2013-11-13 23:36:47 +00:00
|
|
|
if(program.args.length === 0 || !fs.existsSync(program.args[0])) {
|
|
|
|
console.error("Usage: " + process.argv[1] + " [-q] <cfb_file>");
|
2013-09-20 22:43:02 +00:00
|
|
|
process.exit(1);
|
2013-09-05 18:55:36 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 23:36:47 +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);
|
2013-09-20 22:43:02 +00:00
|
|
|
return;
|
2013-09-05 18:55:36 +00:00
|
|
|
}
|
2013-09-20 22:43:02 +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 {
|
2013-09-20 22:43:02 +00:00
|
|
|
console.error("writing " + cfb.FullPaths[i]);
|
|
|
|
fs.writeFileSync(cfb.FullPaths[i], cfb.FileIndex[i].content);
|
2013-09-05 18:55:36 +00:00
|
|
|
}
|
|
|
|
}
|