Merge pull request #814 from atom/original-fs

Add original-fs module
This commit is contained in:
Cheng Zhao 2014-11-12 14:08:03 +08:00
commit c82f5c8da8
5 changed files with 35 additions and 0 deletions

View file

@ -38,6 +38,7 @@
'atom/common/api/lib/clipboard.coffee',
'atom/common/api/lib/crash-reporter.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/shell.coffee',
'atom/common/lib/init.coffee',

View file

@ -0,0 +1,6 @@
fs = require 'fs'
copied = {}
copied[k] = v for k, v of fs
module.exports = copied

View file

@ -35,5 +35,8 @@ if process.type is 'browser'
global.setTimeout = wrapWithActivateUvLoop timers.setTimeout
global.setInterval = wrapWithActivateUvLoop timers.setInterval
# Initialize the "original-fs" module before asar support is loaded.
require 'original-fs'
# Add support for asar packages.
require './asar'

View file

@ -95,6 +95,17 @@ var win = new BrowserWindow({width: 800, height: 600});
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
Even though we tried hard to make `asar` archives in the Node API work like

View file

@ -391,3 +391,17 @@ describe 'asar package', ->
ipc.on 'dirname', (event, dirname) ->
assert.equal dirname, path.dirname(p)
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()