How to use the cfb.read function in cfb

To help you get started, we’ve selected a few cfb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SheetJS / js-cfb / types / bin_cfb.ts View on Github external
const logit = (cmd: string, f: string) => { console.error(sprintf("%-6s %s", cmd, f)); };

if(program.args.length === 0) die(1, "must specify a filename");

if(program.create) {
	logit("create", program.args[0]);
	const newcfb = X.utils.cfb_new();
	X.writeFile(newcfb, program.args[0]);
}

if(!fs.existsSync(program.args[0])) die(1, "must specify a filename");

const opts: X.CFB$ParsingOptions = {type:'file'};
if(program.dev) opts.WTF = true;

const cfb: X.CFB$Container = X.read(program.args[0], opts);
if(program.quiet) exit(0);

if(program.dump) {
	console.log("Full Paths:");
	console.log(cfb.FullPaths.map((x) => "  " + x).join("\n"));
	console.log("File Index:");
	console.log(cfb.FileIndex);
	exit(0);
}
if(program.repair) { X.writeFile(cfb, program.args[0]); exit(0); }

const fix_string = (x: string): string => x.replace(/[\u0000-\u001f]/, ($$) => sprintf("\\u%04X", $$.charCodeAt(0)));
const format_date = (date: Date): string => {
	return sprintf("%02u-%02u-%02u %02u:%02u", date.getUTCMonth()+1, date.getUTCDate(), date.getUTCFullYear()%100, date.getUTCHours(), date.getUTCMinutes());
};

cfb

Compound File Binary File Format extractor

Apache-2.0
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis