|
@@ -457,8 +457,18 @@
|
|
|
}
|
|
|
if (typeof options === 'function') {
|
|
|
callback = options
|
|
|
- options = void 0
|
|
|
+ options = {
|
|
|
+ encoding: null
|
|
|
+ }
|
|
|
+ } else if (util.isString(options)) {
|
|
|
+ options = {
|
|
|
+ encoding: options
|
|
|
+ }
|
|
|
+ } else if (!util.isObject(options)) {
|
|
|
+ throw new TypeError('Bad arguments')
|
|
|
}
|
|
|
+ const {encoding} = options
|
|
|
+
|
|
|
const archive = getOrCreateArchive(asarPath)
|
|
|
if (!archive) {
|
|
|
return invalidArchiveError(asarPath, callback)
|
|
@@ -469,25 +479,14 @@
|
|
|
}
|
|
|
if (info.size === 0) {
|
|
|
return process.nextTick(function () {
|
|
|
- callback(null, new Buffer(0))
|
|
|
+ callback(null, encoding? '' : new Buffer(0))
|
|
|
})
|
|
|
}
|
|
|
if (info.unpacked) {
|
|
|
const realPath = archive.copyFileOut(filePath)
|
|
|
return fs.readFile(realPath, options, callback)
|
|
|
}
|
|
|
- if (!options) {
|
|
|
- options = {
|
|
|
- encoding: null
|
|
|
- }
|
|
|
- } else if (util.isString(options)) {
|
|
|
- options = {
|
|
|
- encoding: options
|
|
|
- }
|
|
|
- } else if (!util.isObject(options)) {
|
|
|
- throw new TypeError('Bad arguments')
|
|
|
- }
|
|
|
- const {encoding} = options
|
|
|
+
|
|
|
const buffer = new Buffer(info.size)
|
|
|
const fd = archive.getFd()
|
|
|
if (!(fd >= 0)) {
|