UNPKG

5.29 kBMarkdownView Raw
1# Archiver v0.9.1 [![Build Status](https://travis-ci.org/ctalkington/node-archiver.svg?branch=master)](https://travis-ci.org/ctalkington/node-archiver)
2
3a streaming interface for archive generation
4
5[![NPM](https://nodei.co/npm/archiver.png)](https://nodei.co/npm/archiver/)
6
7## Install
8
9```bash
10npm install archiver --save
11```
12
13You can also use `npm install https://github.com/ctalkington/node-archiver/archive/master.tar.gz` to test upcoming versions.
14
15## Archiver
16
17#### create(format, options)
18
19Creates an Archiver instance based on the format (zip, tar, etc) passed. Parameters can be passed directly to `Archiver` constructor for convenience.
20
21#### registerFormat(format, module)
22
23Registers an archive format. Format modules are essentially transform streams with a few required methods. They will be further documented once a formal spec is in place.
24
25### Instance Methods
26
27Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) methods.
28
29#### append(input, data)
30
31Appends an input source (text string, buffer, or stream) to the instance. When the instance has received, processed, and emitted the input, the `entry` event is fired.
32
33Replaced `#addFile` in v0.5.
34
35```js
36archive.append('string', { name:'string.txt' });
37archive.append(new Buffer('string'), { name:'buffer.txt' });
38archive.append(fs.createReadStream('mydir/file.txt'), { name:'stream.txt' });
39archive.append(null, { name:'dir/' });
40```
41
42#### bulk(mappings)
43
44Appends multiple entries from passed array of src-dest mappings, based on [Grunt's "Files Array" format](http://gruntjs.com/configuring-tasks#files-array-format). A lazystream wrapper is used to prevent issues with open file limits.
45
46[Globbing patterns](http://gruntjs.com/configuring-tasks#globbing-patterns) and [multiple properties](http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically) are supported through use of the [file-utils](https://github.com/SBoudrias/file-utils) package, based on Grunt's file utilities. Please note that multiple src files to single dest file (ie concat) is not supported.
47
48The `data` property can be set (per src-dest mapping) to define data for matched entries.
49
50```js
51archive.bulk([
52 { src: ['mydir/**'], data: { date: new Date() } },
53 { expand: true, cwd: 'mydir', src: ['**'], dest: 'newdir' }
54]);
55```
56
57#### file(filepath, data)
58
59Appends a file given its filepath. Uses a lazystream wrapper to prevent issues with open file limits. When the instance has received, processed, and emitted the file, the `entry` event is fired.
60
61```js
62archive.file('mydir/file.txt', { name:'file.txt' });
63```
64
65#### finalize()
66
67Finalizes the instance. You should listen for the `end`/`close`/`finish` of the destination stream to properly detect completion.
68
69#### pointer()
70
71Returns the current byte length emitted by archiver. Use this in your end callback to log generated size.
72
73## Events
74
75Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_stream_transform) events.
76
77#### entry
78
79Fired when the input has been received, processed, and emitted. Passes entry data as first argument.
80
81## Zip
82
83### Options
84
85#### comment `string`
86
87Sets the zip comment.
88
89#### forceUTC `boolean`
90
91If true, forces the entry date to UTC. Helps with testing across timezones.
92
93#### store `boolean`
94
95If true, all entry contents will be archived without compression by default.
96
97#### zlib `object`
98
99Passed to node's [zlib](http://nodejs.org/api/zlib.html#zlib_options) module to control compression. Options may vary by node version.
100
101### Entry Data
102
103#### name `string` `required`
104
105Sets the entry name including internal path.
106
107#### date `string|Date`
108
109Sets the entry date. This can be any valid date string or instance. Defaults to current time in locale.
110
111#### store `boolean`
112
113If true, entry contents will be archived without compression.
114
115#### comment `string`
116
117Sets the entry comment.
118
119#### mode `number`
120
121Sets the entry permissions. Defaults to octal 0755 (directory) or 0644 (file).
122
123## Tar
124
125### Options
126
127#### gzip `boolean`
128
129Compresses the tar archive using gzip, default is false.
130
131#### gzipOptions `object`
132
133Passed to node's [zlib](http://nodejs.org/api/zlib.html#zlib_options) module to control compression. Options may vary by node version.
134
135### Entry Data
136
137#### name `string` `required`
138
139Sets the entry name including internal path.
140
141#### date `string|Date`
142
143Sets the entry date. This can be any valid date string or instance. Defaults to current time in locale.
144
145#### mode `number`
146
147Sets the entry permissions. Defaults to octal 0755 (directory) or 0644 (file).
148
149## Libraries
150
151Archiver makes use of several libraries/modules to avoid duplication of efforts.
152
153- [zip-stream](https://npmjs.org/package/zip-stream)
154- [tar-stream](https://npmjs.org/package/tar-stream)
155
156## Things of Interest
157
158- [Examples](https://github.com/ctalkington/node-archiver/blob/master/examples)
159- [Changelog](https://github.com/ctalkington/node-archiver/releases)
160- [Contributing](https://github.com/ctalkington/node-archiver/blob/master/CONTRIBUTING.md)
161- [MIT License](https://github.com/ctalkington/node-archiver/blob/master/LICENSE-MIT)
\No newline at end of file