__toBuffer chunking (fixes #937)

10240 threshold from older version of fixdata
This commit is contained in:
html5-李恒逸 2018-01-02 13:49:28 +08:00 committed by SheetJS
parent f277ebe140
commit a7d3779724
5 changed files with 33 additions and 3 deletions

View File

@ -25,7 +25,7 @@ function write_double_le(b/*:RawBytes|CFBlob*/, v/*:number*/, idx/*:number*/) {
b[idx + 7] = (e >> 4) | bs;
}
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 = function(bufs/*:Array<any>*/) { var x=[],w=10240; for(var i=0;i<bufs[0].length;++i) for(var j=0,L=bufs[0][i].length;j<L;j+=w) x.push.apply(x, bufs[0][i].slice(j,j+w)); 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,''); };
var ___utf16le = __utf16le;

15
test.js
View File

@ -2033,6 +2033,21 @@ describe('corner cases', function() {
it('codepage', function() {
X.read(fs.readFileSync(dir + "biff5/number_format_greek.xls"), {type:TYPE});
});
it('large binary files', function() {
var data = [["Row Number"]];
for(var j = 0; j < 19; ++j) data[0].push("Column " + j+1);
for(var i = 0; i < 499; ++i) {
var o = ["Row " + i];
for(j = 0; j < 19; ++j) o.push(i + j);
data.push(o);
}
var ws = X.utils.aoa_to_sheet(data);
var wb = { Sheets:{ Sheet1: ws }, SheetNames: ["Sheet1"] };
var type = "binary";
["xlsb", "biff8", "biff5", "biff2"].forEach(function(btype) {
void X.read(X.write(wb, {bookType:btype, type:type}), {type:type});
});
});
});
describe('encryption', function() {

15
tests/core.js generated
View File

@ -2033,6 +2033,21 @@ describe('corner cases', function() {
it('codepage', function() {
X.read(fs.readFileSync(dir + "biff5/number_format_greek.xls"), {type:TYPE});
});
it('large binary files', function() {
var data = [["Row Number"]];
for(var j = 0; j < 19; ++j) data[0].push("Column " + j+1);
for(var i = 0; i < 499; ++i) {
var o = ["Row " + i];
for(j = 0; j < 19; ++j) o.push(i + j);
data.push(o);
}
var ws = X.utils.aoa_to_sheet(data);
var wb = { Sheets:{ Sheet1: ws }, SheetNames: ["Sheet1"] };
var type = "binary";
["xlsb", "biff8", "biff5", "biff2"].forEach(function(btype) {
void X.read(X.write(wb, {bookType:btype, type:type}), {type:type});
});
});
});
describe('encryption', function() {

View File

@ -2327,7 +2327,7 @@ function write_double_le(b/*:RawBytes|CFBlob*/, v/*:number*/, idx/*:number*/) {
b[idx + 7] = (e >> 4) | bs;
}
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 = function(bufs/*:Array<any>*/) { var x=[],w=10240; for(var i=0;i<bufs[0].length;++i) for(var j=0,L=bufs[0][i].length;j<L;j+=w) x.push.apply(x, bufs[0][i].slice(j,j+w)); 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,''); };
var ___utf16le = __utf16le;

2
xlsx.js generated
View File

@ -2255,7 +2255,7 @@ function write_double_le(b, v, idx) {
b[idx + 7] = (e >> 4) | bs;
}
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 = function(bufs) { var x=[],w=10240; for(var i=0;i<bufs[0].length;++i) for(var j=0,L=bufs[0][i].length;j<L;j+=w) x.push.apply(x, bufs[0][i].slice(j,j+w)); 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,''); };
var ___utf16le = __utf16le;