├── test
├── input
│ ├── packthis
│ │ ├── emptyfile.txt
│ │ ├── dir2
│ │ │ ├── file3.txt
│ │ │ └── file2.png
│ │ ├── dir1
│ │ │ └── file1.txt
│ │ ├── file0.txt
│ │ └── .hiddenfile.txt
│ ├── packthis-unicode-path
│ │ └── dir1
│ │ │ ├── file1.txt
│ │ │ └── 女の子.txt
│ ├── packthis-glob
│ │ ├── x1
│ │ │ └── file1.txt
│ │ ├── x2
│ │ │ └── file2.txt
│ │ ├── y3
│ │ │ ├── file3.txt
│ │ │ ├── x1
│ │ │ │ └── file4.txt
│ │ │ └── z1
│ │ │ │ └── x2
│ │ │ │ └── file5.txt
│ │ └── z4
│ │ │ └── w1
│ │ │ └── file6.txt
│ ├── packthis-subdir
│ │ ├── dir1
│ │ │ └── file1.txt
│ │ ├── dir2
│ │ │ └── subdir
│ │ │ │ ├── file3.txt
│ │ │ │ └── file2.png
│ │ └── file0.txt
│ ├── extractthis-unpack-dir.asar.unpacked
│ │ └── dir2
│ │ │ ├── file3.txt
│ │ │ └── file2.png
│ ├── extractthis.asar
│ ├── extractthis-unpack.asar
│ ├── extractthis-unpack.asar.unpacked
│ │ └── dir2
│ │ │ └── file2.png
│ └── extractthis-unpack-dir.asar
├── expected
│ ├── extractthis
│ │ ├── dir2
│ │ │ ├── file3.txt
│ │ │ └── file2.png
│ │ ├── emptyfile.txt
│ │ ├── file0.txt
│ │ └── dir1
│ │ │ └── file1.txt
│ ├── packthis-unicode-path-filelist.txt
│ ├── packthis.asar
│ ├── packthis-unpack.asar
│ ├── packthis-transformed.asar
│ ├── extractthis-filelist.txt
│ ├── packthis-without-hidden.asar
│ ├── packthis-unpack-dir-glob.asar
│ ├── packthis-unicode-path.asar
│ ├── packthis-unpack-dir-globstar.asar
│ ├── packthis-unpack.asar.unpacked
│ │ └── dir2
│ │ │ └── file2.png
│ ├── extractthis-filelist-with-option.txt
│ ├── packthis-unpack-dir.asar
│ └── packthis-all-unpacked.asar
├── util
│ ├── compareFiles.js
│ ├── transformStream.js
│ └── compareDirectories.js
├── api-spec.js
└── cli-spec.js
├── .gitattributes
├── .gitignore
├── .npmignore
├── .travis.yml
├── appveyor.yml
├── snapcraft.yaml
├── lib
├── crawlfs.js
├── snapshot.js
├── filesystem.js
├── disk.js
└── asar.js
├── LICENSE.md
├── package.json
├── CHANGELOG.md
├── bin
└── asar.js
└── README.md
/test/input/packthis/emptyfile.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/input/packthis/dir2/file3.txt:
--------------------------------------------------------------------------------
1 | 123
--------------------------------------------------------------------------------
/test/expected/extractthis/dir2/file3.txt:
--------------------------------------------------------------------------------
1 | 123
--------------------------------------------------------------------------------
/test/expected/extractthis/emptyfile.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/input/packthis/dir1/file1.txt:
--------------------------------------------------------------------------------
1 | file one.
--------------------------------------------------------------------------------
/test/input/packthis/file0.txt:
--------------------------------------------------------------------------------
1 | file0 content
--------------------------------------------------------------------------------
/test/expected/extractthis/file0.txt:
--------------------------------------------------------------------------------
1 | file0 content
--------------------------------------------------------------------------------
/test/input/packthis-unicode-path/dir1/file1.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/input/packthis-unicode-path/dir1/女の子.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | test/input/**/*.txt text eol=lf
2 |
--------------------------------------------------------------------------------
/test/expected/extractthis/dir1/file1.txt:
--------------------------------------------------------------------------------
1 | file one.
--------------------------------------------------------------------------------
/test/input/packthis-glob/x1/file1.txt:
--------------------------------------------------------------------------------
1 | fileone
2 |
--------------------------------------------------------------------------------
/test/input/packthis-glob/x2/file2.txt:
--------------------------------------------------------------------------------
1 | filetwo
2 |
--------------------------------------------------------------------------------
/test/input/packthis-glob/y3/file3.txt:
--------------------------------------------------------------------------------
1 | filethree
2 |
--------------------------------------------------------------------------------
/test/input/packthis-glob/y3/x1/file4.txt:
--------------------------------------------------------------------------------
1 | filefour
2 |
--------------------------------------------------------------------------------
/test/input/packthis-glob/z4/w1/file6.txt:
--------------------------------------------------------------------------------
1 | filesix
2 |
--------------------------------------------------------------------------------
/test/input/packthis-subdir/dir1/file1.txt:
--------------------------------------------------------------------------------
1 | file one.
--------------------------------------------------------------------------------
/test/input/packthis-subdir/dir2/subdir/file3.txt:
--------------------------------------------------------------------------------
1 | 123
--------------------------------------------------------------------------------
/test/input/packthis-subdir/file0.txt:
--------------------------------------------------------------------------------
1 | file0 content
--------------------------------------------------------------------------------
/test/input/packthis-glob/y3/z1/x2/file5.txt:
--------------------------------------------------------------------------------
1 | filefive
2 |
--------------------------------------------------------------------------------
/test/input/packthis/.hiddenfile.txt:
--------------------------------------------------------------------------------
1 | This file is hidden
--------------------------------------------------------------------------------
/test/input/extractthis-unpack-dir.asar.unpacked/dir2/file3.txt:
--------------------------------------------------------------------------------
1 | 123
--------------------------------------------------------------------------------
/test/expected/packthis-unicode-path-filelist.txt:
--------------------------------------------------------------------------------
1 | /dir1
2 | /dir1/file1.txt
3 | /dir1/女の子.txt
--------------------------------------------------------------------------------
/test/expected/packthis.asar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/expected/packthis.asar
--------------------------------------------------------------------------------
/test/input/extractthis.asar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/input/extractthis.asar
--------------------------------------------------------------------------------
/test/expected/packthis-unpack.asar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/expected/packthis-unpack.asar
--------------------------------------------------------------------------------
/test/input/extractthis-unpack.asar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/input/extractthis-unpack.asar
--------------------------------------------------------------------------------
/test/input/packthis/dir2/file2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/input/packthis/dir2/file2.png
--------------------------------------------------------------------------------
/test/expected/packthis-transformed.asar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/expected/packthis-transformed.asar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules
2 | /build
3 | /tmp
4 | *.swp
5 | *.log
6 | *~
7 | .DS_Store
8 | .node-version
9 | npm-debug.log
10 | .idea
11 |
--------------------------------------------------------------------------------
/test/expected/extractthis-filelist.txt:
--------------------------------------------------------------------------------
1 | /dir1
2 | /dir1/file1.txt
3 | /dir2
4 | /dir2/file2.png
5 | /dir2/file3.txt
6 | /emptyfile.txt
7 | /file0.txt
--------------------------------------------------------------------------------
/test/expected/extractthis/dir2/file2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/expected/extractthis/dir2/file2.png
--------------------------------------------------------------------------------
/test/expected/packthis-without-hidden.asar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/expected/packthis-without-hidden.asar
--------------------------------------------------------------------------------
/test/expected/packthis-unpack-dir-glob.asar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/expected/packthis-unpack-dir-glob.asar
--------------------------------------------------------------------------------
/test/expected/packthis-unicode-path.asar:
--------------------------------------------------------------------------------
1 | t p j {"files":{"dir1":{"files":{"file1.txt":{"size":0,"offset":"0"},"女の子.txt":{"size":0,"offset":"0"}}}}}
--------------------------------------------------------------------------------
/test/expected/packthis-unpack-dir-globstar.asar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/expected/packthis-unpack-dir-globstar.asar
--------------------------------------------------------------------------------
/test/input/packthis-subdir/dir2/subdir/file2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/input/packthis-subdir/dir2/subdir/file2.png
--------------------------------------------------------------------------------
/test/expected/packthis-unpack.asar.unpacked/dir2/file2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/expected/packthis-unpack.asar.unpacked/dir2/file2.png
--------------------------------------------------------------------------------
/test/input/extractthis-unpack.asar.unpacked/dir2/file2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/input/extractthis-unpack.asar.unpacked/dir2/file2.png
--------------------------------------------------------------------------------
/test/input/extractthis-unpack-dir.asar.unpacked/dir2/file2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Contrast-Security-OSS/asar/master/test/input/extractthis-unpack-dir.asar.unpacked/dir2/file2.png
--------------------------------------------------------------------------------
/test/expected/extractthis-filelist-with-option.txt:
--------------------------------------------------------------------------------
1 | pack : /dir1
2 | pack : /dir1/file1.txt
3 | unpack : /dir2
4 | unpack : /dir2/file2.png
5 | unpack : /dir2/file3.txt
6 | pack : /emptyfile.txt
7 | pack : /file0.txt
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | /build
2 | /spec
3 | /tmp
4 | *.coffee
5 | *.log
6 | *~
7 | *.swp
8 | .DS_Store
9 | .node-version
10 | .npmignore
11 | npm-debug.log
12 | /test
13 | .gitattributes
14 | appveyor.yml
15 | .travis.yml
16 | coffeelint.json
17 | .idea
18 |
--------------------------------------------------------------------------------
/test/expected/packthis-unpack-dir.asar:
--------------------------------------------------------------------------------
1 | {"files":{"dir1":{"files":{"file1.txt":{"size":9,"offset":"0"}}},"dir2":{"unpacked":true,"files":{"file2.png":{"size":182,"unpacked":true},"file3.txt":{"size":3,"unpacked":true}}},"emptyfile.txt":{"size":0,"offset":"9"},"file0.txt":{"size":13,"offset":"9"}}} file one.file0 content
--------------------------------------------------------------------------------
/test/input/extractthis-unpack-dir.asar:
--------------------------------------------------------------------------------
1 | {"files":{"dir1":{"files":{"file1.txt":{"size":9,"offset":"0"}}},"dir2":{"unpacked":true,"files":{"file2.png":{"size":182,"unpacked":true},"file3.txt":{"size":3,"unpacked":true}}},"emptyfile.txt":{"size":0,"offset":"9"},"file0.txt":{"size":13,"offset":"9"}}} file one.file0 content
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "6"
4 | - "8"
5 | - "10"
6 |
7 | branches:
8 | only:
9 | - master
10 |
11 | install:
12 | - export DISPLAY=':99.0'
13 | - Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
14 | - npm install
15 |
16 | notifications:
17 | email:
18 | on_success: never
19 | on_failure: change
20 |
--------------------------------------------------------------------------------
/test/expected/packthis-all-unpacked.asar:
--------------------------------------------------------------------------------
1 | T P I {"files":{".hiddenfile.txt":{"size":19,"unpacked":true},"dir1":{"unpacked":true,"files":{"file1.txt":{"size":9,"unpacked":true}}},"dir2":{"unpacked":true,"files":{"file2.png":{"size":182,"unpacked":true},"file3.txt":{"size":3,"unpacked":true}}},"emptyfile.txt":{"size":0,"unpacked":true},"file0.txt":{"size":13,"unpacked":true}}}
--------------------------------------------------------------------------------
/test/util/compareFiles.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const assert = require('assert')
3 | const fs = process.versions.electron ? require('original-fs') : require('fs')
4 |
5 | module.exports = function (filepathA, filepathB) {
6 | const actual = fs.readFileSync(filepathA, 'utf8')
7 | const expected = fs.readFileSync(filepathB, 'utf8')
8 | return assert.equal(actual, expected)
9 | }
10 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | build: off
2 |
3 | branches:
4 | only:
5 | - master
6 |
7 | skip_tags: true
8 |
9 | environment:
10 | matrix:
11 | - nodejs_version: "6"
12 | - nodejs_version: "8"
13 | - nodejs_version: "10"
14 |
15 | install:
16 | - ps: Install-Product node $env:nodejs_version
17 | - npm install
18 |
19 | test_script:
20 | - node --version
21 | - npm --version
22 | - npm test
23 |
--------------------------------------------------------------------------------
/snapcraft.yaml:
--------------------------------------------------------------------------------
1 | name: asar
2 | version: git
3 | summary: Manipulate asar archive files
4 | description: |
5 | Asar is a simple extensive archive format, it works like tar that
6 | concatenates all files together without compression, while having
7 | random access support.
8 |
9 | confinement: classic
10 |
11 | parts:
12 | asar:
13 | plugin: nodejs
14 | source: .
15 |
16 | apps:
17 | asar:
18 | command: lib/node_modules/asar/bin/asar.js
19 |
--------------------------------------------------------------------------------
/test/util/transformStream.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const Transform = require('stream').Transform
3 | const basename = require('path').basename
4 |
5 | class Reverser extends Transform {
6 | constructor () {
7 | super()
8 | this._data = ''
9 | }
10 |
11 | _transform (buf, enc, cb) {
12 | this._data += buf
13 | return cb()
14 | }
15 |
16 | _flush (cb) {
17 | const txt = this._data.toString().split('').reverse().join('')
18 | this.push(txt)
19 | return cb()
20 | }
21 | }
22 |
23 | module.exports = function (filename) {
24 | if (basename(filename) === 'file0.txt') {
25 | return new Reverser()
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/lib/crawlfs.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const fs = process.versions.electron ? require('original-fs') : require('fs')
3 | const glob = require('glob')
4 |
5 | module.exports = function (dir, options, callback) {
6 | const metadata = {}
7 | return glob(dir, options, function (error, filenames) {
8 | if (error) { return callback(error) }
9 | for (const filename of filenames) {
10 | const stat = fs.lstatSync(filename)
11 | if (stat.isFile()) {
12 | metadata[filename] = {type: 'file', stat: stat}
13 | } else if (stat.isDirectory()) {
14 | metadata[filename] = {type: 'directory', stat: stat}
15 | } else if (stat.isSymbolicLink()) {
16 | metadata[filename] = {type: 'link', stat: stat}
17 | }
18 | }
19 | return callback(null, filenames, metadata)
20 | })
21 | }
22 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 GitHub Inc.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "main": "./lib/asar.js",
3 | "name": "asar",
4 | "description": "Creating Electron app packages",
5 | "version": "0.14.8",
6 | "bin": {
7 | "asar": "./bin/asar.js"
8 | },
9 | "engines": {
10 | "node": ">=4.6"
11 | },
12 | "license": "MIT",
13 | "homepage": "https://github.com/electron/asar",
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/electron/asar.git"
17 | },
18 | "bugs": {
19 | "url": "https://github.com/electron/asar/issues"
20 | },
21 | "scripts": {
22 | "test": "xvfb-maybe electron-mocha --reporter spec && mocha --reporter spec && npm run lint",
23 | "lint": "standard"
24 | },
25 | "standard": {
26 | "env": {
27 | "mocha": true
28 | }
29 | },
30 | "dependencies": {
31 | "chromium-pickle-js": "^0.2.0",
32 | "commander": "^2.9.0",
33 | "cuint": "^0.2.1",
34 | "glob": "^6.0.4",
35 | "minimatch": "^3.0.3",
36 | "mkdirp": "^0.5.0",
37 | "mksnapshot": "github:Contrast-Security-OSS/node-mksnapshot#v0.3.3",
38 | "tmp": "0.0.28"
39 | },
40 | "devDependencies": {
41 | "electron": "^1.6.2",
42 | "electron-mocha": "^6.0.4",
43 | "lodash": "^4.2.1",
44 | "mocha": "^5.2.0",
45 | "rimraf": "^2.5.1",
46 | "standard": "^8.6.0",
47 | "xvfb-maybe": "^0.1.3"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changes By Version
2 |
3 | ## 0.14.0 - 2017-11-02
4 |
5 | ### Added
6 |
7 | * Snapcraft metadata (#130)
8 | * `uncache` and `uncacheAll` (#118)
9 |
10 | ### Fixed
11 |
12 | * Use of asar inside of an Electron app (#118)
13 |
14 | ## 0.13.1 - 2017-11-02
15 |
16 | ### Fixed
17 |
18 | - Do not return before the write stream fully closes (#113)
19 |
20 | ## 0.13.0 - 2017-01-09
21 |
22 | ### Changed
23 |
24 | - Dropped support for Node `0.10.0` and `0.12.0`. The minimum supported version
25 | is now Node `4.6.0`. (#100)
26 | - This project was ported from CoffeeScript to JavaScript. The behavior and
27 | APIs should be the same as previous releases. (#100)
28 |
29 | ## 0.12.4 - 2016-12-28
30 |
31 | ### Fixed
32 |
33 | - Unpack glob patterns containing `{}` characters not working properly (#99)
34 |
35 | ## 0.12.3 - 2016-08-29
36 |
37 | ### Fixed
38 |
39 | - Multibyte characters in paths are now supported (#86)
40 |
41 | ## 0.12.2 - 2016-08-22
42 |
43 | ### Fixed
44 |
45 | - Upgraded `minimatch` to `^3.0.3` from `^3.0.0` for [RegExp DOS fix](https://nodesecurity.io/advisories/minimatch_regular-expression-denial-of-service).
46 |
47 | ## 0.12.1 - 2016-07-25
48 |
49 | ### Fixed
50 |
51 | - Fix `Maximum call stack size exceeded` error regression (#80)
52 |
53 | ## 0.12.0 - 2016-07-20
54 |
55 | ### Added
56 |
57 | - Added `transform` option to specify a `stream.Transform` function to the
58 | `createPackageWithOptions` API (#73)
59 |
60 | ## 0.11.0 - 2016-04-06
61 |
62 | ### Fixed
63 |
64 | - Upgraded `mksnapshot` dependency to remove logged `graceful-fs` deprecation
65 | warnings (#61)
66 |
--------------------------------------------------------------------------------
/lib/snapshot.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const fs = process.versions.electron ? require('original-fs') : require('fs')
3 | const path = require('path')
4 | const mksnapshot = require('mksnapshot')
5 | const vm = require('vm')
6 |
7 | const stripBOM = function (content) {
8 | if (content.charCodeAt(0) === 0xFEFF) {
9 | content = content.slice(1)
10 | }
11 | return content
12 | }
13 |
14 | const wrapModuleCode = function (script) {
15 | script = script.replace(/^#!.*/, '')
16 | return `(function(exports, require, module, __filename, __dirname) { ${script} \n});`
17 | }
18 |
19 | const dumpObjectToJS = function (content) {
20 | let result = 'var __ATOM_SHELL_SNAPSHOT = {\n'
21 | for (const filename in content) {
22 | const func = content[filename].toString()
23 | result += ` '${filename}': ${func},\n`
24 | }
25 | result += '};\n'
26 | return result
27 | }
28 |
29 | const createSnapshot = function (src, dest, filenames, metadata, options, callback) {
30 | const content = {}
31 | try {
32 | src = path.resolve(src)
33 | for (const filename of filenames) {
34 | const file = metadata[filename]
35 | if ((file.type === 'file' || file.type === 'link') && filename.substr(-3) === '.js') {
36 | const script = wrapModuleCode(stripBOM(fs.readFileSync(filename, 'utf8')))
37 | const relativeFilename = path.relative(src, filename)
38 | try {
39 | const compiled = vm.runInThisContext(script, {filename: relativeFilename})
40 | content[relativeFilename] = compiled
41 | } catch (error) {
42 | console.error('Ignoring ' + relativeFilename + ' for ' + error.name)
43 | }
44 | }
45 | }
46 | } catch (error) {
47 | return callback(error)
48 | }
49 |
50 | // run mksnapshot
51 | const str = dumpObjectToJS(content)
52 | const version = options.version
53 | const arch = options.arch
54 | const builddir = options.builddir
55 | let snapshotdir = options.snapshotdir
56 |
57 | if (typeof snapshotdir === 'undefined' || snapshotdir === null) { snapshotdir = path.dirname(dest) }
58 | const target = path.resolve(snapshotdir, 'snapshot_blob.bin')
59 | return mksnapshot(str, target, version, arch, builddir, callback)
60 | }
61 |
62 | module.exports = createSnapshot
63 |
--------------------------------------------------------------------------------
/test/util/compareDirectories.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const fs = process.versions.electron ? require('original-fs') : require('fs')
3 | const path = require('path')
4 |
5 | const _ = require('lodash')
6 |
7 | const crawlFilesystem = require('../../lib/crawlfs')
8 |
9 | module.exports = function (dirA, dirB, cb) {
10 | crawlFilesystem(dirA, function (err, pathsA, metadataA) {
11 | if (err != null) return cb(err)
12 | crawlFilesystem(dirB, function (err, pathsB, metadataB) {
13 | if (err != null) return cb(err)
14 | const relativeA = _.map(pathsA, function (pathAItem) { return path.relative(dirA, pathAItem) })
15 | const relativeB = _.map(pathsB, function (pathBItem) { return path.relative(dirB, pathBItem) })
16 | const onlyInA = _.difference(relativeA, relativeB)
17 | const onlyInB = _.difference(relativeB, relativeA)
18 | const inBoth = _.intersection(pathsA, pathsB)
19 | const differentFiles = []
20 | const errorMsgBuilder = []
21 | err = null
22 | for (let i in inBoth) {
23 | const filename = inBoth[i]
24 | const typeA = metadataA[filename].type
25 | const typeB = metadataB[filename].type
26 | // skip if both are directories
27 | if (typeA === 'directory' && typeB === 'directory') { continue }
28 | // something is wrong if the types don't match up
29 | if (typeA !== typeB) {
30 | differentFiles.push(filename)
31 | continue
32 | }
33 | const fileContentA = fs.readFileSync(path.join(dirA, filename), 'utf8')
34 | const fileContentB = fs.readFileSync(path.join(dirB, filename), 'utf8')
35 | if (fileContentA !== fileContentB) { differentFiles.push(filename) }
36 | }
37 | if (onlyInA.length) {
38 | errorMsgBuilder.push(`\tEntries only in '${dirA}':`)
39 | for (const file of onlyInA) { errorMsgBuilder.push(`\t ${file}`) }
40 | }
41 | if (onlyInB.length) {
42 | errorMsgBuilder.push(`\tEntries only in '${dirB}':`)
43 | for (const file of onlyInB) { errorMsgBuilder.push(`\t ${file}`) }
44 | }
45 | if (differentFiles.length) {
46 | errorMsgBuilder.push('\tDifferent file content:')
47 | for (const file of differentFiles) { errorMsgBuilder.push(`\t ${file}`) }
48 | }
49 | if (errorMsgBuilder.length) { err = new Error('\n' + errorMsgBuilder.join('\n')) }
50 | cb(err)
51 | })
52 | })
53 | }
54 |
--------------------------------------------------------------------------------
/bin/asar.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var asar = require('../lib/asar')
3 | var program = require('commander')
4 |
5 | program.version('v' + require('../package.json').version)
6 | .description('Manipulate asar archive files')
7 |
8 | program.command('pack