version bump 1.0.1: find multiple \x01-\x06 chars
This commit is contained in:
parent
46719dfe3c
commit
8cd01668f0
@ -16,6 +16,7 @@ program
|
||||
.option('-c, --create', 'create file')
|
||||
.option('-a, --append', 'add files to CFB (overwrite existing data)')
|
||||
.option('-d, --delete', 'delete files from CFB')
|
||||
.option('-O, --to-stdout', 'extract raw contents to stdout')
|
||||
.option('-z, --dump', 'dump internal representation but do not extract')
|
||||
.option('-q, --quiet', 'process but do not report')
|
||||
.option('--dev', 'development mode')
|
||||
@ -52,7 +53,7 @@ if(program.dump) {
|
||||
}
|
||||
if(program.repair) { X.writeFile(cfb, program.args[0]); exit(0); }
|
||||
|
||||
function fix_string(x/*:string*/)/*:string*/ { return x.replace(/[\u0000-\u001f]/, function($$) { return sprintf("\\u%04X", $$.charCodeAt(0)); }); }
|
||||
function fix_string(x/*:string*/)/*:string*/ { return x.replace(/[\u0000-\u001f]/g, function($$) { return sprintf("\\u%04X", $$.charCodeAt(0)); }); }
|
||||
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());
|
||||
};
|
||||
@ -111,16 +112,18 @@ if(program.delete) {
|
||||
|
||||
if(program.args.length > 1) {
|
||||
program.args.slice(1).forEach(function(x/*:string*/) {
|
||||
var data/*:?CFBEntry*/ = X.find(cfb, x);
|
||||
var data/*:?CFBEntry*/ = X.find(cfb, x.replace(/\\u000\d/g,"!"));
|
||||
if(!data) { console.error(x + ": file not found"); return; }
|
||||
if(data.type !== 2) { console.error(x + ": not a file"); return; }
|
||||
var idx = cfb.FileIndex.indexOf(data), path = cfb.FullPaths[idx];
|
||||
if(program.toStdout) return process.stdout.write(/*::new Buffer((*/data.content/*:: :any))*/);
|
||||
mkdirp(path.slice(0, path.lastIndexOf("/")));
|
||||
write(path, data);
|
||||
});
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(program.toStdout) exit(0);
|
||||
for(var i=0; i!==cfb.FullPaths.length; ++i) {
|
||||
if(!cfb.FileIndex[i].name) continue;
|
||||
if(cfb.FullPaths[i].slice(-1) === "/") mkdirp(cfb.FullPaths[i]);
|
||||
|
@ -12,4 +12,4 @@ var s2a = function s2a(s/*:string*/) {
|
||||
return s.split("").map(function(x){ return x.charCodeAt(0) & 0xff; });
|
||||
};
|
||||
|
||||
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/;
|
||||
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;
|
||||
|
@ -1 +1 @@
|
||||
exports.version = '1.0.0';
|
||||
exports.version = '1.0.1';
|
||||
|
@ -64,7 +64,7 @@ var s2a = function s2a(s/*:string*/) {
|
||||
return s.split("").map(function(x){ return x.charCodeAt(0) & 0xff; });
|
||||
};
|
||||
|
||||
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/;
|
||||
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;
|
||||
var __toBuffer = function(bufs/*:Array<Array<RawBytes> >*/)/*:RawBytes*/ { var x = []; for(var i = 0; i < bufs[0].length; ++i) { x.push.apply(x, bufs[0][i]); } return x; };
|
||||
var ___toBuffer = __toBuffer;
|
||||
var __utf16le = function(b/*:RawBytes|CFBlob*/,s/*:number*/,e/*:number*/)/*:string*/ { var ss/*:Array<string>*/=[]; for(var i=s; i<e; i+=2) ss.push(String.fromCharCode(__readUInt16LE(b,i))); return ss.join("").replace(chr0,''); };
|
||||
@ -179,7 +179,7 @@ type CFBFiles = {[n:string]:CFBEntry};
|
||||
/* [MS-CFB] v20130118 */
|
||||
var CFB = (function _CFB(){
|
||||
var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/;
|
||||
exports.version = '1.0.0';
|
||||
exports.version = '1.0.1';
|
||||
/* [MS-CFB] 2.6.4 */
|
||||
function namecmp(l/*:string*/, r/*:string*/)/*:number*/ {
|
||||
var L = l.split("/"), R = r.split("/");
|
||||
|
4
cfb.js
4
cfb.js
@ -64,7 +64,7 @@ var s2a = function s2a(s) {
|
||||
return s.split("").map(function(x){ return x.charCodeAt(0) & 0xff; });
|
||||
};
|
||||
|
||||
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/;
|
||||
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;
|
||||
var __toBuffer = function(bufs) { var x = []; for(var i = 0; i < bufs[0].length; ++i) { x.push.apply(x, bufs[0][i]); } return x; };
|
||||
var ___toBuffer = __toBuffer;
|
||||
var __utf16le = function(b,s,e) { var ss=[]; for(var i=s; i<e; i+=2) ss.push(String.fromCharCode(__readUInt16LE(b,i))); return ss.join("").replace(chr0,''); };
|
||||
@ -161,7 +161,7 @@ function new_buf(sz) {
|
||||
/* [MS-CFB] v20130118 */
|
||||
var CFB = (function _CFB(){
|
||||
var exports = {};
|
||||
exports.version = '1.0.0';
|
||||
exports.version = '1.0.1';
|
||||
/* [MS-CFB] 2.6.4 */
|
||||
function namecmp(l, r) {
|
||||
var L = l.split("/"), R = r.split("/");
|
||||
|
4
dist/cfb.js
vendored
4
dist/cfb.js
vendored
@ -64,7 +64,7 @@ var s2a = function s2a(s) {
|
||||
return s.split("").map(function(x){ return x.charCodeAt(0) & 0xff; });
|
||||
};
|
||||
|
||||
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/;
|
||||
var chr0 = /\u0000/g, chr1 = /[\u0001-\u0006]/g;
|
||||
var __toBuffer = function(bufs) { var x = []; for(var i = 0; i < bufs[0].length; ++i) { x.push.apply(x, bufs[0][i]); } return x; };
|
||||
var ___toBuffer = __toBuffer;
|
||||
var __utf16le = function(b,s,e) { var ss=[]; for(var i=s; i<e; i+=2) ss.push(String.fromCharCode(__readUInt16LE(b,i))); return ss.join("").replace(chr0,''); };
|
||||
@ -161,7 +161,7 @@ function new_buf(sz) {
|
||||
/* [MS-CFB] v20130118 */
|
||||
var CFB = (function _CFB(){
|
||||
var exports = {};
|
||||
exports.version = '1.0.0';
|
||||
exports.version = '1.0.1';
|
||||
/* [MS-CFB] 2.6.4 */
|
||||
function namecmp(l, r) {
|
||||
var L = l.split("/"), R = r.split("/");
|
||||
|
2
dist/cfb.min.js
vendored
2
dist/cfb.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/cfb.min.map
vendored
2
dist/cfb.min.map
vendored
File diff suppressed because one or more lines are too long
2
dist/xlscfb.js
vendored
2
dist/xlscfb.js
vendored
@ -38,7 +38,7 @@ type CFBFiles = {[n:string]:CFBEntry};
|
||||
/* [MS-CFB] v20130118 */
|
||||
var CFB = (function _CFB(){
|
||||
var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/;
|
||||
exports.version = '1.0.0';
|
||||
exports.version = '1.0.1';
|
||||
/* [MS-CFB] 2.6.4 */
|
||||
function namecmp(l/*:string*/, r/*:string*/)/*:number*/ {
|
||||
var L = l.split("/"), R = r.split("/");
|
||||
|
@ -1,4 +1,3 @@
|
||||
apachepoi_61300.xls
|
||||
apachepoi_testEXCEL_3.xls
|
||||
apachepoi_testEXCEL_4.xls
|
||||
xlrd_biff4_no_format_no_window2.xls
|
||||
|
48
package.json
48
package.json
@ -1,9 +1,13 @@
|
||||
{
|
||||
"name": "cfb",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"author": "sheetjs",
|
||||
"description": "Compound File Binary File Format extractor",
|
||||
"keywords": [ "cfb", "compression", "office" ],
|
||||
"keywords": [
|
||||
"cfb",
|
||||
"compression",
|
||||
"office"
|
||||
],
|
||||
"bin": {
|
||||
"cfb": "./bin/cfb.njs"
|
||||
},
|
||||
@ -15,20 +19,23 @@
|
||||
"fs": false
|
||||
},
|
||||
"dependencies": {
|
||||
"printj":"~1.1.0",
|
||||
"commander":"~2.11.0"
|
||||
"commander": "^2.12.1",
|
||||
"printj": "~1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"crc-32":"~1.1.1",
|
||||
"mocha":"~2.5.3",
|
||||
"crc-32": "~1.1.1",
|
||||
"mocha": "~2.5.3",
|
||||
"blanket": "~1.2.3",
|
||||
"@sheetjs/uglify-js":"~2.7.3",
|
||||
"@types/node":"^8.0.7",
|
||||
"@types/commander":"^2.9.0",
|
||||
"dtslint": "^0.1.2",
|
||||
"@sheetjs/uglify-js": "~2.7.3",
|
||||
"@types/node": "^8.0.7",
|
||||
"@types/commander": "^2.9.0",
|
||||
"dtslint": "~0.1.2",
|
||||
"typescript": "2.2.0"
|
||||
},
|
||||
"repository": { "type":"git", "url":"git://github.com/SheetJS/js-cfb.git" },
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/SheetJS/js-cfb.git"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "make init",
|
||||
"test": "make test",
|
||||
@ -39,9 +46,22 @@
|
||||
"pattern": "cfb.js"
|
||||
}
|
||||
},
|
||||
"files": [ "LICENSE", "README.md", "bin/", "dist/", "types/index.d.ts", "types/tsconfig.json", "cfb.js", "xlscfb.flow.js" ],
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"bin/",
|
||||
"dist/",
|
||||
"types/index.d.ts",
|
||||
"types/tsconfig.json",
|
||||
"cfb.js",
|
||||
"xlscfb.flow.js"
|
||||
],
|
||||
"homepage": "http://sheetjs.com/opensource",
|
||||
"bugs": { "url": "https://github.com/SheetJS/js-cfb/issues" },
|
||||
"bugs": {
|
||||
"url": "https://github.com/SheetJS/js-cfb/issues"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"engines": { "node": ">=0.8" }
|
||||
"engines": {
|
||||
"node": ">=0.8"
|
||||
}
|
||||
}
|
||||
|
35
test.js
35
test.js
@ -131,3 +131,38 @@ describe('input formats', function() {
|
||||
CFB.read(fs.readFileSync(dir + '/' + cp), {type: 'buffer'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('api', function() {
|
||||
it('should generate a file with custom root', function() {
|
||||
var cfb = CFB.utils.cfb_new({root:'SheetJS'});
|
||||
if(cfb.FileIndex[0].name != 'SheetJS') throw new Error("Bad root name");
|
||||
var newcfb = CFB.read(CFB.write(cfb, {type:'base64'}), {type:'base64'});
|
||||
if(newcfb.FileIndex[0].name != 'SheetJS') throw new Error("Bad root name");
|
||||
});
|
||||
it('should be able to delete a file', function() {
|
||||
var cfb = CFB.read(fs.readFileSync(dir + '/' + cp, 'binary'), {type: 'binary'});
|
||||
if(!CFB.find(cfb, '/Workbook')) throw new Error("Cannot find /Workbook");
|
||||
CFB.utils.cfb_del(cfb, '/Workbook');
|
||||
if(CFB.utils.cfb_del(cfb, '/Workbook')) throw new Error("Found /Workbook");
|
||||
if(CFB.find(cfb, '/Workbook')) throw new Error("Failed deleting /Workbook");
|
||||
var newcfb = CFB.read(CFB.write(cfb, {type:'binary'}), {type:'binary'});
|
||||
if(CFB.find(newcfb, '/Workbook')) throw new Error("Found /Workbook");
|
||||
});
|
||||
it('should be able to move a file', function() {
|
||||
var cfb = CFB.read(fs.readFileSync(dir + '/' + cp, 'binary'), {type: 'binary'});
|
||||
if(!CFB.find(cfb, '/Workbook')) throw new Error("Cannot find /Workbook");
|
||||
CFB.utils.cfb_mov(cfb, '/Workbook', '/Book');
|
||||
if(CFB.utils.cfb_mov(cfb, '/Workbook', '/Work')) throw new Error("Found /Workbook");
|
||||
if(CFB.find(cfb, '/Workbook')) throw new Error("Failed deleting /Workbook");
|
||||
var newcfb = CFB.read(CFB.write(cfb, {type:'binary'}), {type:'binary'});
|
||||
if(CFB.find(newcfb, '/Workbook')) throw new Error("Found /Workbook");
|
||||
});
|
||||
it('should be able to add a file', function() {
|
||||
var cfb = CFB.read(fs.readFileSync(dir + '/' + cp, 'binary'), {type: 'binary'});
|
||||
CFB.utils.cfb_add(cfb, '/dafuq', [1,2,3]);
|
||||
var newcfb = CFB.read(CFB.write(cfb, {type:'binary'}), {type:'binary'});
|
||||
var file = CFB.find(cfb, '/dafuq');
|
||||
if(!file || !file.content) throw new Error("Cannot find /dafuq");
|
||||
if(file.content.length != 3) throw new Error("Bad content length " + file.content.length);
|
||||
});
|
||||
});
|
||||
|
@ -38,7 +38,7 @@ type CFBFiles = {[n:string]:CFBEntry};
|
||||
/* [MS-CFB] v20130118 */
|
||||
var CFB = (function _CFB(){
|
||||
var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/;
|
||||
exports.version = '1.0.0';
|
||||
exports.version = '1.0.1';
|
||||
/* [MS-CFB] 2.6.4 */
|
||||
function namecmp(l/*:string*/, r/*:string*/)/*:number*/ {
|
||||
var L = l.split("/"), R = r.split("/");
|
||||
|
@ -8,7 +8,7 @@ var DO_NOT_EXPORT_CFB = true;
|
||||
/* [MS-CFB] v20130118 */
|
||||
var CFB = (function _CFB(){
|
||||
var exports = {};
|
||||
exports.version = '1.0.0';
|
||||
exports.version = '1.0.1';
|
||||
/* [MS-CFB] 2.6.4 */
|
||||
function namecmp(l, r) {
|
||||
var L = l.split("/"), R = r.split("/");
|
||||
|
Loading…
Reference in New Issue
Block a user