commit
c82f5c8da8
5 changed files with 35 additions and 0 deletions
1
atom.gyp
1
atom.gyp
|
@ -38,6 +38,7 @@
|
||||||
'atom/common/api/lib/clipboard.coffee',
|
'atom/common/api/lib/clipboard.coffee',
|
||||||
'atom/common/api/lib/crash-reporter.coffee',
|
'atom/common/api/lib/crash-reporter.coffee',
|
||||||
'atom/common/api/lib/id-weak-map.coffee',
|
'atom/common/api/lib/id-weak-map.coffee',
|
||||||
|
'atom/common/api/lib/original-fs.coffee',
|
||||||
'atom/common/api/lib/screen.coffee',
|
'atom/common/api/lib/screen.coffee',
|
||||||
'atom/common/api/lib/shell.coffee',
|
'atom/common/api/lib/shell.coffee',
|
||||||
'atom/common/lib/init.coffee',
|
'atom/common/lib/init.coffee',
|
||||||
|
|
6
atom/common/api/lib/original-fs.coffee
Normal file
6
atom/common/api/lib/original-fs.coffee
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
fs = require 'fs'
|
||||||
|
|
||||||
|
copied = {}
|
||||||
|
copied[k] = v for k, v of fs
|
||||||
|
|
||||||
|
module.exports = copied
|
|
@ -35,5 +35,8 @@ if process.type is 'browser'
|
||||||
global.setTimeout = wrapWithActivateUvLoop timers.setTimeout
|
global.setTimeout = wrapWithActivateUvLoop timers.setTimeout
|
||||||
global.setInterval = wrapWithActivateUvLoop timers.setInterval
|
global.setInterval = wrapWithActivateUvLoop timers.setInterval
|
||||||
|
|
||||||
|
# Initialize the "original-fs" module before asar support is loaded.
|
||||||
|
require 'original-fs'
|
||||||
|
|
||||||
# Add support for asar packages.
|
# Add support for asar packages.
|
||||||
require './asar'
|
require './asar'
|
||||||
|
|
|
@ -95,6 +95,17 @@ var win = new BrowserWindow({width: 800, height: 600});
|
||||||
win.loadUrl('asar:/path/to/example.asar/static/index.html');
|
win.loadUrl('asar:/path/to/example.asar/static/index.html');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Treating `asar` archive as normal file
|
||||||
|
|
||||||
|
For some cases like verifying the `asar` archive's checksum, we need to read the
|
||||||
|
content of `asar` archive as file. For this purpose you can use the built-in
|
||||||
|
`original-fs` module which provides original `fs` APIs without `asar` support:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var originalFs = require('original-fs');
|
||||||
|
originalFs.readFileSync('/path/to/example.asar');
|
||||||
|
```
|
||||||
|
|
||||||
## Limitations on Node API
|
## Limitations on Node API
|
||||||
|
|
||||||
Even though we tried hard to make `asar` archives in the Node API work like
|
Even though we tried hard to make `asar` archives in the Node API work like
|
||||||
|
|
|
@ -391,3 +391,17 @@ describe 'asar package', ->
|
||||||
ipc.on 'dirname', (event, dirname) ->
|
ipc.on 'dirname', (event, dirname) ->
|
||||||
assert.equal dirname, path.dirname(p)
|
assert.equal dirname, path.dirname(p)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe 'original-fs module', ->
|
||||||
|
originalFs = require 'original-fs'
|
||||||
|
|
||||||
|
it 'uses the original fs api', ->
|
||||||
|
changedApis = ['readFile', 'stat', 'lstat', 'realpath', 'exists']
|
||||||
|
unchangedApis = ['read', 'write', 'writeFile', 'close']
|
||||||
|
assert.notStrictEqual fs[api], originalFs[api] for api in changedApis
|
||||||
|
assert.strictEqual fs[api], originalFs[api] for api in unchangedApis
|
||||||
|
|
||||||
|
it 'treats .asar as file', ->
|
||||||
|
file = path.join fixtures, 'asar', 'a.asar'
|
||||||
|
stats = originalFs.statSync file
|
||||||
|
assert stats.isFile()
|
||||||
|
|
Loading…
Reference in a new issue