Merge pull request #10160 from liusy182/liusy182-10128-asar

Return empty string when fs.readFile with 'utf8' option from asar file
This commit is contained in:
John Kleinschmidt 2017-08-07 21:42:15 -04:00 committed by GitHub
commit 72d2e176dd
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)) {