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)) {

View file

@ -99,6 +99,15 @@ describe('asar package', function () {
})
})
it('reads from a empty file with encoding', function (done) {
var p = path.join(fixtures, 'asar', 'empty.asar', 'file1')
fs.readFile(p, 'utf8', function (err, content) {
assert.equal(err, null)
assert.equal(content, '')
done()
})
})
it('reads a linked file', function (done) {
var p = path.join(fixtures, 'asar', 'a.asar', 'link1')
fs.readFile(p, function (err, content) {