Fix calling fs.open in fs.readFile wrapper
This commit is contained in:
parent
38f83cacf9
commit
150739e19e
1 changed files with 4 additions and 2 deletions
|
@ -129,6 +129,7 @@ fs.existsSync = (p) ->
|
||||||
|
|
||||||
archive.stat(filePath) isnt false
|
archive.stat(filePath) isnt false
|
||||||
|
|
||||||
|
open = fs.open
|
||||||
readFile = fs.readFile
|
readFile = fs.readFile
|
||||||
fs.readFile = (p, options, callback) ->
|
fs.readFile = (p, options, callback) ->
|
||||||
[isAsar, asarPath, filePath] = splitPath p
|
[isAsar, asarPath, filePath] = splitPath p
|
||||||
|
@ -155,12 +156,13 @@ fs.readFile = (p, options, callback) ->
|
||||||
encoding = options.encoding
|
encoding = options.encoding
|
||||||
|
|
||||||
buffer = new Buffer(info.size)
|
buffer = new Buffer(info.size)
|
||||||
fs.open archive.path, flag, (error, fd) ->
|
open archive.path, flag, (error, fd) ->
|
||||||
return callback error if error
|
return callback error if error
|
||||||
fs.read fd, buffer, 0, info.size, info.offset, (error) ->
|
fs.read fd, buffer, 0, info.size, info.offset, (error) ->
|
||||||
fs.close fd, ->
|
fs.close fd, ->
|
||||||
callback error, if encoding then buffer.toString encoding else buffer
|
callback error, if encoding then buffer.toString encoding else buffer
|
||||||
|
|
||||||
|
openSync = fs.openSync
|
||||||
readFileSync = fs.readFileSync
|
readFileSync = fs.readFileSync
|
||||||
fs.readFileSync = (p, options) ->
|
fs.readFileSync = (p, options) ->
|
||||||
[isAsar, asarPath, filePath] = splitPath p
|
[isAsar, asarPath, filePath] = splitPath p
|
||||||
|
@ -183,7 +185,7 @@ fs.readFileSync = (p, options) ->
|
||||||
encoding = options.encoding
|
encoding = options.encoding
|
||||||
|
|
||||||
buffer = new Buffer(info.size)
|
buffer = new Buffer(info.size)
|
||||||
fd = fs.openSync archive.path, flag
|
fd = openSync archive.path, flag
|
||||||
try
|
try
|
||||||
fs.readSync fd, buffer, 0, info.size, info.offset
|
fs.readSync fd, buffer, 0, info.size, info.offset
|
||||||
catch e
|
catch e
|
||||||
|
|
Loading…
Reference in a new issue