How to use the cfb.writeFile 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
.option('-d, --delete', 'delete files from CFB')
	.option('--dev', 'development mode')
	.option('--read', 'read but do not print out contents');

program.parse(process.argv);

const exit = process.exit;
const die = (errno: number, msg: string) => { console.error(n + ": " + msg); exit(errno); };
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);
github SheetJS / js-cfb / types / bin_cfb.ts View on Github external
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());
};

if(program.listFiles) {
	let basetime = new Date(1980,0,1);
	let cnt = 0, rootsize = 0, filesize = 0;
	console.log("  Length     Date   Time    Name");
	console.log(" --------    ----   ----    ----");
	cfb.FileIndex.forEach((file: X.CFB$Entry, i: number) => {
		switch(file.type) {
			case 5:
				basetime = file.ct || file.mt || basetime;
				rootsize = file.size;

cfb

Compound File Binary File Format extractor

Apache-2.0
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis