Skip to content

Commit

Permalink
Merge pull request #39 from shaggyrec/fix-temp-clean-up-for-concurren…
Browse files Browse the repository at this point in the history
…tly-reading

Fix temp clean up for concurrently reading
  • Loading branch information
DaSpawn committed Apr 4, 2019
2 parents 4520190 + 5b342c0 commit efa78b1
Show file tree
Hide file tree
Showing 5 changed files with 381 additions and 345 deletions.
10 changes: 4 additions & 6 deletions lib/workbook.js
Expand Up @@ -8,7 +8,7 @@

const Path = require('path')
const Fs = require('fs')
const Temp = require('temp')
const Tmp = require('tmp')
const Stream = require('stream')
const unzipper = require('unzipper')
const Sax = require('sax')
Expand Down Expand Up @@ -94,8 +94,6 @@ function XlsxStreamReaderWorkBook (options) {
}
})

Temp.track()

self._handleWorkBookStream()
}
Util.inherits(XlsxStreamReaderWorkBook, Stream)
Expand Down Expand Up @@ -160,9 +158,10 @@ XlsxStreamReaderWorkBook.prototype._handleWorkBookStream = function () {
self.parsedSharedStrings === false ||
self.waitingWorkSheets.length > 0
) {
var stream = Temp.createWriteStream()
const { name } = Tmp.fileSync({})
const stream = Fs.createWriteStream(name)

self.waitingWorkSheets.push({sheetNo: sheetNo, name: entry.path, path: stream.path, sheetPath: sheetPath})
self.waitingWorkSheets.push({sheetNo: sheetNo, name: entry.path, path: name, sheetPath: sheetPath})

entry.pipe(stream)
} else {
Expand Down Expand Up @@ -191,7 +190,6 @@ XlsxStreamReaderWorkBook.prototype._handleWorkBookStream = function () {
workSheet.on('end', function (node) {
++currentBook
if (currentBook === self.waitingWorkSheets.length) {
Temp.cleanupSync()
setImmediate(self.emit.bind(self), 'end')
} else {
setImmediate(processBooks)
Expand Down

0 comments on commit efa78b1

Please sign in to comment.