fixes 10128

This commit is contained in:
Siyuan Liu 2017-07-31 09:32:45 +08:00
parent d38c9a4644
commit 5a48c1feed
2 changed files with 28 additions and 20 deletions

View file

@ -457,26 +457,6 @@
}
if (typeof options === 'function') {
callback = options
options = void 0
}
const archive = getOrCreateArchive(asarPath)
if (!archive) {
return invalidArchiveError(asarPath, callback)
}
const info = archive.getFileInfo(filePath)
if (!info) {
return notFoundError(asarPath, filePath, callback)
}
if (info.size === 0) {
return process.nextTick(function () {
callback(null, new Buffer(0))
})
}
if (info.unpacked) {
const realPath = archive.copyFileOut(filePath)
return fs.readFile(realPath, options, callback)
}
if (!options) {
options = {
encoding: null
}
@ -488,6 +468,25 @@
throw new TypeError('Bad arguments')
}
const {encoding} = options
const archive = getOrCreateArchive(asarPath)
if (!archive) {
return invalidArchiveError(asarPath, callback)
}
const info = archive.getFileInfo(filePath)
if (!info) {
return notFoundError(asarPath, filePath, callback)
}
if (info.size === 0) {
return process.nextTick(function () {
callback(null, encoding? '' : new Buffer(0))
})
}
if (info.unpacked) {
const realPath = archive.copyFileOut(filePath)
return fs.readFile(realPath, options, callback)
}
const buffer = new Buffer(info.size)
const fd = archive.getFd()
if (!(fd >= 0)) {