UNPKG

3.52 kBMarkdownView Raw
1# asar - Atom-Shell Archive
2
3[![build status](http://img.shields.io/travis/atom/asar.svg?style=flat-square)](https://travis-ci.org/atom/asar)
4[![dependencies](http://img.shields.io/david/atom/asar.svg?style=flat-square)](https://david-dm.org/atom/asar)
5[![npm version](http://img.shields.io/npm/v/asar.svg?style=flat-square)](https://npmjs.org/package/asar)
6
7Asar is a simple extensive archive format, it works like `tar` that concatenates
8all files together without compression, while having random access support.
9
10## Features
11
12* Support random access
13* Use JSON to store files' information
14* Very easy to write a parser
15
16## Command line utility
17
18### Install
19
20```bash
21$ npm install asar
22```
23
24### Usage
25
26```bash
27$ asar --help
28
29 Usage: asar [options] [command]
30
31 Commands:
32
33 pack|p <dir> <output>
34 create asar archive
35
36 list|l <archive>
37 list files of asar archive
38
39 extract-file|ef <archive> <filename>
40 extract one file from archive
41
42 extract|e <archive> <dest>
43 extract archive
44
45
46 Options:
47
48 -h, --help output usage information
49 -V, --version output the version number
50
51```
52
53## Using programatically
54
55### Example
56
57```js
58var asar = require('asar');
59
60var src = 'some/path/';
61var dest = 'name.asar';
62
63asar.createPackage(src, dest, function() {
64 console.log('done.');
65})
66```
67
68Please note that there is currently *no* error handling provided!
69
70## Using with grunt
71
72There is also an unofficial grunt plugin to generate asar archives at [bwin/grunt-asar][grunt-asar].
73
74## Format
75
76Asar uses [Pickle][pickle] to safely serialize binary value to file, there is
77also a [node.js binding][node-pickle] of `Pickle` class.
78
79The format of asar is very flat:
80
81```
82| UInt32: header_size | String: header | Bytes: file1 | ... | Bytes: file42 |
83```
84
85The `header_size` and `header` are serialized with [Pickle][pickle] class, and
86`header_size`'s [Pickle][pickle] object is 8 bytes.
87
88The `header` is a JSON string, and the `header_size` is the size of `header`'s
89`Pickle` object.
90
91Structure of `header` is something like this:
92
93```json
94{
95 "files": {
96 "tmp": {
97 "files": {}
98 },
99 "usr" : {
100 "files": {
101 "bin": {
102 "files": {
103 "ls": {
104 "offset": "0",
105 "size": 100,
106 "executable": true
107 },
108 "cd": {
109 "offset": "100",
110 "size": 100,
111 "executable": true
112 }
113 }
114 }
115 }
116 },
117 "etc": {
118 "files": {
119 "hosts": {
120 "offset": "200",
121 "size": 32
122 }
123 }
124 }
125 }
126}
127```
128
129`offset` and `size` records the information to read the file from archive, the
130`offset` starts from 0 so you have to manually add the size of `header_size` and
131`header` to the `offset` to get the real offset of the file.
132
133`offset` is a UINT64 number represented in string, because there is no way to
134precisely represent UINT64 in JavaScript `Number`. `size` is a JavaScript
135`Number` that is no larger than `Number.MAX_SAFE_INTEGER`, which has a value of
136`9007199254740991` and is about 8PB in size. We didn't store `size` in UINT64
137because file size in Node.js is represented as `Number` and it is not safe to
138convert `Number` to UINT64.
139
140[pickle]: https://chromium.googlesource.com/chromium/src/+/master/base/pickle.h
141[node-pickle]: https://www.npmjs.org/package/chromium-pickle
142[grunt-asar]: https://github.com/bwin/grunt-asar