Skip to content

Commit 82d57d5

Browse files
imp: release large values early for GC
1 parent db70c6d commit 82d57d5

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

lib/xlsx/xlsx.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,13 @@ class XLSX {
249249
if (!stream[Symbol.asyncIterator] && stream.pipe) {
250250
stream = stream.pipe(new PassThrough());
251251
}
252-
const chunks = [];
252+
let chunks = [];
253253
for await (const chunk of stream) {
254254
chunks.push(chunk);
255255
}
256-
return this.load(Buffer.concat(chunks), options);
256+
const buffer = Buffer.concat(chunks);
257+
chunks = null;
258+
return this.load(buffer, options);
257259
}
258260

259261
async load(data, options) {
@@ -282,7 +284,8 @@ class XLSX {
282284
buffer = await officeCrypto.decrypt(buffer, {password: options.password});
283285
}
284286

285-
const zip = await JSZip.loadAsync(buffer);
287+
let zip = await JSZip.loadAsync(buffer);
288+
buffer = null;
286289
for (const entry of Object.values(zip.files)) {
287290
/* eslint-disable no-await-in-loop */
288291
if (!entry.dir) {
@@ -413,6 +416,7 @@ class XLSX {
413416
}
414417
}
415418
}
419+
zip = null;
416420

417421
this.reconcile(model, options);
418422

18.8 MB
Binary file not shown.

spec/integration/workbook-xlsx-reader.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ describe('WorkbookReader', () => {
130130
{maxRows: 20}
131131
);
132132
});
133+
134+
describe('Big file support', () => {
135+
it('should read large file correctly', function(done) {
136+
this.timeout(20000);
137+
const workbook = new ExcelJS.Workbook();
138+
workbook.xlsx
139+
.read(
140+
fs.createReadStream('./spec/integration/data/extra-large.xlsx')
141+
)
142+
.then(result => {
143+
expect(result._worksheets[1]._rows.length).to.equal(512781);
144+
expect(
145+
result._worksheets[1]._rows[500000]._cells[4]._value.value
146+
).to.equal(11);
147+
done();
148+
});
149+
});
150+
});
133151
});
134152
});
135153

0 commit comments

Comments
 (0)