Creating Electron app packages
npm install @electron/asar

Asar is a simple extensive archive format, it works like tar that concatenatesall files together without compression, while having random access support.
tar
* Support random access* Use JSON to store files' information* Very easy to write a parser
This module requires Node 22.12.0 or later.
``bash$ npm install --engine-strict @electron/asar`
bash$ npm install --engine-strict @electron/asar
`bash$ asar --help
bash$ asar --help
Usage: asar [options] [command]
Commands:
pack|p
list|l list files of asar archive
extract-file|ef extract one file from archive
extract|e extract archive
Options:
-h, --help output usage information -V, --version output the version number
`
#### Excluding multiple resources from being packed
Given:` app(a) ├── x1(b) ├── x2(c) ├── y3(d) │ ├── x1(e) │ └── z1(f) │ └── x2(g) └── z4(h) └── w1`
app(a) ├── x1(b) ├── x2(c) ├── y3(d) │ ├── x1(e) │ └── z1(f) │ └── x2(g) └── z4(h) └── w1
Exclude: a, b`bash$ asar pack app app.asar --unpack-dir "{x1,x2}"`
bash$ asar pack app app.asar --unpack-dir "{x1,x2}"
Exclude: a, b, d, f`bash$ asar pack app app.asar --unpack-dir "**/{x1,x2}"`
bash$ asar pack app app.asar --unpack-dir "**/{x1,x2}"
Exclude: a, b, d, f, h`bash$ asar pack app app.asar --unpack-dir "{/x1,/x2,z4/w1}"`
bash$ asar pack app app.asar --unpack-dir "{/x1,/x2,z4/w1}"
`javascriptimport { createPackage } from '@electron/asar';
javascriptimport { createPackage } from '@electron/asar';
const src = 'some/path/';const dest = 'name.asar';
await createPackage(src, dest);console.log('done.');`
Please note that there is currently no error handling provided!
option, that is a function, which either returnsnothing, or a
. The latter will be used on files that will bein the
file to transform them (e.g. compress).
javascriptimport { createPackageWithOptions } from '@electron/asar';const src = 'some/path/';const dest = 'name.asar';function transform (filename) { return new CustomTransformStream()}await createPackageWithOptions(src, dest, { transform: transform });console.log('done.');
function transform (filename) { return new CustomTransformStream()}
await createPackageWithOptions(src, dest, { transform: transform });console.log('done.');
FormatAsar uses [Pickle][pickle] to safely serialize binary value to file.The format of asar is very flat:
Asar uses [Pickle][pickle] to safely serialize binary value to file.
The format of asar is very flat:
| UInt32: header_size | String: header | Bytes: file1 | ... | Bytes: file42 |
The
and
are serialized with [Pickle][pickle] class, and
's [Pickle][pickle] object is 8 bytes.The
is a JSON string, and the
is the size of
's
object.Structure of
Structure of
is something like this:
json{ "files": { "tmp": { "files": {} }, "usr" : { "files": { "bin": { "files": { "ls": { "offset": "0", "size": 100, "executable": true, "integrity": { "algorithm": "SHA256", "hash": "...", "blockSize": 1024, "blocks": ["...", "..."] } }, "cd": { "offset": "100", "size": 100, "executable": true, "integrity": { "algorithm": "SHA256", "hash": "...", "blockSize": 1024, "blocks": ["...", "..."] } } } } } }, "etc": { "files": { "hosts": { "offset": "200", "size": 32, "integrity": { "algorithm": "SHA256", "hash": "...", "blockSize": 1024, "blocks": ["...", "..."] } } } } }}
records the information to read the file from archive, the
starts from 0 so you have to manually add the size of
to the
to get the real offset of the file.
is a UINT64 number represented in string, because there is no way toprecisely represent UINT64 in JavaScript
.
is a JavaScript
that is no larger than
, which has a value of
and is about 8PB in size. We didn't store
in UINT64because file size in Node.js is represented as
and it is not safe toconvert
to UINT64.
is an object consisting of a few keys:* A hashing
, currently only
is supported.* A hex encoded
value representing the hash of the entire file.* An array of hex encoded hashes for the
of the file. i.e. for a blockSize of 4KB this array contains the hash of every block if you split the file into N 4KB blocks.* A integer value
representing the size in bytes of each block in the
[pickle]: https://chromium.googlesource.com/chromium/src/+/main/base/pickle.h