From 5cb97545fd739184de0a0109a65fb5bbe7d43dff Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 12 Nov 2014 11:09:59 +0800 Subject: [PATCH 1/3] Add original-fs module --- atom.gyp | 1 + atom/common/api/lib/original-fs.coffee | 6 ++++++ atom/common/lib/init.coffee | 3 +++ 3 files changed, 10 insertions(+) create mode 100644 atom/common/api/lib/original-fs.coffee 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' From 90c24de0f08b94c64d51ead152686a71b696435b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 12 Nov 2014 11:31:31 +0800 Subject: [PATCH 2/3] spec: original-fs module --- spec/asar-spec.coffee | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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() From bd1f0e78a8f34da243ec062f9f89cacb352650bd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 12 Nov 2014 11:58:03 +0800 Subject: [PATCH 3/3] docs: original-fs module --- docs/tutorial/application-packaging.md | 11 +++++++++++ 1 file changed, 11 insertions(+) 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