From 47dd984a6c08f4c79638819f91ca539bb4be37e2 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Wed, 29 Jan 2014 22:06:14 -0500 Subject: [PATCH] version bump 0.4.2: using jszip module on node - updated test_files - new dependency in node: jszip --- bits/31_version.js | 2 +- bits/35_ziputils.js | 3 +++ bits/88_read.js | 4 +++- package.json | 5 +++-- tests.lst | 1 + tests/files | 2 +- xlsx.js | 9 +++++++-- 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/bits/31_version.js b/bits/31_version.js index 60707c6..cdc4408 100644 --- a/bits/31_version.js +++ b/bits/31_version.js @@ -1 +1 @@ -XLSX.version = '0.4.1'; +XLSX.version = '0.4.2'; diff --git a/bits/35_ziputils.js b/bits/35_ziputils.js index dbf469b..9b95346 100644 --- a/bits/35_ziputils.js +++ b/bits/35_ziputils.js @@ -1,6 +1,8 @@ function getdata(data) { if(!data) return null; if(data.data) return data.data; + if(data.asNodeBuffer && typeof Buffer !== 'undefined' && data.name.substr(-4)===".bin") return data.asNodeBuffer(); + if(data.asBinary && data.name.substr(-4) !== ".bin") return data.asBinary(); if(data._data && data._data.getContent) { /* TODO: something far more intelligent */ if(data.name.substr(-4) === ".bin") return Array.prototype.slice.call(data._data.getContent()); @@ -20,6 +22,7 @@ var _fs, jszip; if(typeof JSZip !== 'undefined') jszip = JSZip; if (typeof exports !== 'undefined') { if (typeof module !== 'undefined' && module.exports) { + if(typeof Buffer !== 'undefined' && typeof jszip === 'undefined') jszip = require('jszip'); if(typeof jszip === 'undefined') jszip = require('./jszip').JSZip; _fs = require('fs'); } diff --git a/bits/88_read.js b/bits/88_read.js index 8637d1e..ce93f59 100644 --- a/bits/88_read.js +++ b/bits/88_read.js @@ -2,7 +2,9 @@ function readSync(data, options) { var zip, d = data; var o = options||{}; switch((o.type||"base64")){ - case "file": d = _fs.readFileSync(data).toString('base64'); + case "file": + if(typeof Buffer !== 'undefined') { zip=new jszip(d=_fs.readFileSync(data)); break; } + d = _fs.readFileSync(data).toString('base64'); /* falls through */ case "base64": zip = new jszip(d, { base64:true }); break; case "binary": zip = new jszip(d, { base64:false }); break; diff --git a/package.json b/package.json index e2f572e..3d90c72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xlsx", - "version": "0.4.1", + "version": "0.4.2", "author": "sheetjs", "description": "XLSB / XLSX / XLSM parser", "keywords": [ "xlsx", "xlsb", "xlsm", "office", "excel", "spreadsheet" ], @@ -9,8 +9,9 @@ }, "main": "./xlsx", "dependencies": { - "ssf":">=0.1.1", + "ssf":">=0.5.5", "codepage":"", + "jszip":"~0.2.1", "commander":"" }, "devDependencies": { diff --git a/tests.lst b/tests.lst index 849a71a..d6d633e 100644 --- a/tests.lst +++ b/tests.lst @@ -1,4 +1,5 @@ formula_stress_test.xlsb +time_stress_test_1.xlsb LONumbers-2010.xlsx LONumbers-2011.xlsx LONumbers.xlsx diff --git a/tests/files b/tests/files index 78b9631..51eb476 160000 --- a/tests/files +++ b/tests/files @@ -1 +1 @@ -Subproject commit 78b96314f232d09634beb8db7e65359434adc33a +Subproject commit 51eb4765cd8828155a72d5b2aa273e999daaa93e diff --git a/xlsx.js b/xlsx.js index 23c43c4..a0eb8a6 100644 --- a/xlsx.js +++ b/xlsx.js @@ -420,7 +420,7 @@ SSF.load_table = function(tbl) { for(var i=0; i!=0x0188; ++i) if(tbl[i]) SSF.loa make_ssf(SSF); var XLSX = {}; (function(XLSX){ -XLSX.version = '0.4.1'; +XLSX.version = '0.4.2'; var current_codepage, current_cptable, cptable; if(typeof module !== "undefined" && typeof require !== 'undefined') { if(typeof cptable === 'undefined') cptable = require('codepage'); @@ -434,6 +434,8 @@ function _getchar(x) { return String.fromCharCode(x); } function getdata(data) { if(!data) return null; if(data.data) return data.data; + if(data.asNodeBuffer && typeof Buffer !== 'undefined' && data.name.substr(-4)===".bin") return data.asNodeBuffer(); + if(data.asBinary && data.name.substr(-4) !== ".bin") return data.asBinary(); if(data._data && data._data.getContent) { /* TODO: something far more intelligent */ if(data.name.substr(-4) === ".bin") return Array.prototype.slice.call(data._data.getContent()); @@ -453,6 +455,7 @@ var _fs, jszip; if(typeof JSZip !== 'undefined') jszip = JSZip; if (typeof exports !== 'undefined') { if (typeof module !== 'undefined' && module.exports) { + if(typeof Buffer !== 'undefined' && typeof jszip === 'undefined') jszip = require('jszip'); if(typeof jszip === 'undefined') jszip = require('./jszip').JSZip; _fs = require('fs'); } @@ -2638,7 +2641,9 @@ function readSync(data, options) { var zip, d = data; var o = options||{}; switch((o.type||"base64")){ - case "file": d = _fs.readFileSync(data).toString('base64'); + case "file": + if(typeof Buffer !== 'undefined') { zip=new jszip(d=_fs.readFileSync(data)); break; } + d = _fs.readFileSync(data).toString('base64'); /* falls through */ case "base64": zip = new jszip(d, { base64:true }); break; case "binary": zip = new jszip(d, { base64:false }); break;