diff --git a/atom.gyp b/atom.gyp index 2142819702ed..bccb001cb53a 100644 --- a/atom.gyp +++ b/atom.gyp @@ -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', diff --git a/atom/common/api/lib/original-fs.coffee b/atom/common/api/lib/original-fs.coffee new file mode 100644 index 000000000000..5aefb357402d --- /dev/null +++ b/atom/common/api/lib/original-fs.coffee @@ -0,0 +1,6 @@ +fs = require 'fs' + +copied = {} +copied[k] = v for k, v of fs + +module.exports = copied diff --git a/atom/common/lib/init.coffee b/atom/common/lib/init.coffee index b8d67355c05f..19c0ee986bc8 100644 --- a/atom/common/lib/init.coffee +++ b/atom/common/lib/init.coffee @@ -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' diff --git a/docs/tutorial/application-packaging.md b/docs/tutorial/application-packaging.md index 423162443fd7..a2dd5dabca15 100644 --- a/docs/tutorial/application-packaging.md +++ b/docs/tutorial/application-packaging.md @@ -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 diff --git a/spec/asar-spec.coffee b/spec/asar-spec.coffee index 12cbff7989ae..b48394f8e21d 100644 --- a/spec/asar-spec.coffee +++ b/spec/asar-spec.coffee @@ -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()