2013-09-05 18:55:36 +00:00
|
|
|
#!/usr/bin/env node
|
2017-08-09 06:50:59 +00:00
|
|
|
/* cfb.js (C) 2013-present SheetJS -- http://sheetjs.com */
|
|
|
|
/* eslint-env node */
|
|
|
|
/* vim: set ts=2 ft=javascript: */
|
|
|
|
var X = require('../');
|
2013-11-13 23:36:47 +00:00
|
|
|
var fs = require('fs'), program = require('commander');
|
|
|
|
program
|
2017-08-09 06:50:59 +00:00
|
|
|
.version(X.version)
|
2013-11-13 23:36:47 +00:00
|
|
|
.usage('[options] <file>')
|
2014-11-03 04:02:42 +00:00
|
|
|
.option('-q, --quiet', 'process but do not report')
|
2017-08-09 06:50:59 +00:00
|
|
|
.option('-l, --list-files', 'list files')
|
2014-11-03 04:02:42 +00:00
|
|
|
.option('-d, --dump', 'dump internal representation but do not extract')
|
|
|
|
.option('--dev', 'development mode')
|
2017-08-09 06:50:59 +00:00
|
|
|
.option('--read', 'read but do not print out contents');
|
|
|
|
|
|
|
|
program.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
|
|
|
}
|
|
|
|
|
2017-02-24 05:11:45 +00:00
|
|
|
var opts = ({type:'file'}/*:any*/);
|
2014-11-03 04:02:42 +00:00
|
|
|
if(program.dev) opts.WTF = true;
|
|
|
|
|
2017-08-09 06:50:59 +00:00
|
|
|
var cfb = X.read(program.args[0], opts);
|
|
|
|
if(program.quiet) process.exit(0);
|
|
|
|
|
2014-11-03 04:02:42 +00:00
|
|
|
if(program.dump) {
|
2017-02-24 05:11:45 +00:00
|
|
|
console.log("Full Paths:");
|
2013-11-13 23:36:47 +00:00
|
|
|
console.log(cfb.FullPaths.map(function(x) { return " " + x; }).join("\n"));
|
2017-02-24 05:11:45 +00:00
|
|
|
console.log("Full Path Directory:");
|
2013-11-13 23:36:47 +00:00
|
|
|
console.log(cfb.FullPathDir);
|
2017-08-09 06:50:59 +00:00
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
if(program.listFiles) {
|
|
|
|
var PRINTJ = require("printj"), sprintf = PRINTJ.sprintf;
|
|
|
|
|
|
|
|
var format_date = function(date/*:Date*/)/*:string*/ {
|
|
|
|
return sprintf("%02u-%02u-%02u %02u:%02u", date.getUTCMonth()+1, date.getUTCDate(), date.getUTCFullYear()%100, date.getUTCHours(), date.getUTCMinutes());
|
|
|
|
};
|
|
|
|
|
|
|
|
var basetime = new Date(1980,0,1);
|
|
|
|
var cnt = 0;
|
|
|
|
var rootsize = 0, filesize = 0;
|
|
|
|
console.log(" Length Date Time Name");
|
|
|
|
console.log(" -------- ---- ---- ----");
|
|
|
|
cfb.FileIndex.forEach(function(file, i) {
|
|
|
|
switch(file.type) {
|
|
|
|
case 5:
|
|
|
|
basetime = file.ct || file.mt || basetime;
|
|
|
|
rootsize = file.size;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
console.log(sprintf("%9lu %s %s", file.size, format_date(basetime), cfb.FullPaths[i]));
|
|
|
|
filesize += file.size;
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log(" -------- -------");
|
|
|
|
console.log(sprintf("%9lu %lu file%s", rootsize || filesize, cnt, (cnt !== 1 ? "s" : "")));
|
|
|
|
|
|
|
|
process.exit(0);
|
2013-09-05 18:55:36 +00:00
|
|
|
}
|
2017-08-09 06:50:59 +00:00
|
|
|
for(var i=0; i!==cfb.FullPaths.length; ++i) {
|
2013-09-20 22:43:02 +00:00
|
|
|
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]);
|
2017-07-28 17:53:08 +00:00
|
|
|
fs.writeFileSync(cfb.FullPaths[i], /*::new Buffer((*/cfb.FileIndex[i].content/*:: :any))*/);
|
2013-09-05 18:55:36 +00:00
|
|
|
}
|
|
|
|
}
|