@alienkarma/archiver 7.0.1-fork.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +89 -0
- package/index.js +39 -0
- package/lib/core.js +851 -0
- package/lib/error.js +37 -0
- package/lib/plugins/json.js +79 -0
- package/lib/plugins/tar.js +118 -0
- package/lib/plugins/zip.js +72 -0
- package/lib/utils.js +66 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012-2014 Chris Talkington, contributors.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Archiver
|
|
2
|
+
|
|
3
|
+
A streaming interface for archive generation
|
|
4
|
+
|
|
5
|
+
Visit the [API documentation](https://www.archiverjs.com/) for a list of all methods available.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install archiver --save
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import fs from "fs";
|
|
17
|
+
import { ZipArchive } from "archiver";
|
|
18
|
+
|
|
19
|
+
// create a file to stream archive data to.
|
|
20
|
+
const output = fs.createWriteStream(__dirname + "/example.zip");
|
|
21
|
+
const archive = new ZipArchive({
|
|
22
|
+
zlib: { level: 9 }, // Sets the compression level.
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// listen for all archive data to be written
|
|
26
|
+
// 'close' event is fired only when a file descriptor is involved
|
|
27
|
+
output.on("close", function () {
|
|
28
|
+
console.log(archive.pointer() + " total bytes");
|
|
29
|
+
console.log(
|
|
30
|
+
"archiver has been finalized and the output file descriptor has closed.",
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// This event is fired when the data source is drained no matter what was the data source.
|
|
35
|
+
// It is not part of this library but rather from the NodeJS Stream API.
|
|
36
|
+
// @see: https://nodejs.org/api/stream.html#stream_event_end
|
|
37
|
+
output.on("end", function () {
|
|
38
|
+
console.log("Data has been drained");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// good practice to catch warnings (ie stat failures and other non-blocking errors)
|
|
42
|
+
archive.on("warning", function (err) {
|
|
43
|
+
if (err.code === "ENOENT") {
|
|
44
|
+
// log warning
|
|
45
|
+
} else {
|
|
46
|
+
// throw error
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// good practice to catch this error explicitly
|
|
52
|
+
archive.on("error", function (err) {
|
|
53
|
+
throw err;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// pipe archive data to the file
|
|
57
|
+
archive.pipe(output);
|
|
58
|
+
|
|
59
|
+
// append a file from stream
|
|
60
|
+
const file1 = __dirname + "/file1.txt";
|
|
61
|
+
archive.append(fs.createReadStream(file1), { name: "file1.txt" });
|
|
62
|
+
|
|
63
|
+
// append a file from string
|
|
64
|
+
archive.append("string cheese!", { name: "file2.txt" });
|
|
65
|
+
|
|
66
|
+
// append a file from buffer
|
|
67
|
+
const buffer3 = Buffer.from("buff it!");
|
|
68
|
+
archive.append(buffer3, { name: "file3.txt" });
|
|
69
|
+
|
|
70
|
+
// append a file
|
|
71
|
+
archive.file("file1.txt", { name: "file4.txt" });
|
|
72
|
+
|
|
73
|
+
// append files from a sub-directory and naming it `new-subdir` within the archive
|
|
74
|
+
archive.directory("subdir/", "new-subdir");
|
|
75
|
+
|
|
76
|
+
// append files from a sub-directory, putting its contents at the root of archive
|
|
77
|
+
archive.directory("subdir/", false);
|
|
78
|
+
|
|
79
|
+
// append files from a glob pattern
|
|
80
|
+
archive.glob("file*.txt", { cwd: __dirname });
|
|
81
|
+
|
|
82
|
+
// finalize the archive (ie we are done appending files but streams have to finish yet)
|
|
83
|
+
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
|
|
84
|
+
archive.finalize();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Formats
|
|
88
|
+
|
|
89
|
+
Archiver ships with out of the box support for TAR and ZIP archives.
|
package/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Archiver from "./lib/core.js";
|
|
2
|
+
import Zip from "./lib/plugins/zip.js";
|
|
3
|
+
import Tar from "./lib/plugins/tar.js";
|
|
4
|
+
import Json from "./lib/plugins/json.js";
|
|
5
|
+
|
|
6
|
+
export { Archiver };
|
|
7
|
+
|
|
8
|
+
export class ZipArchive extends Archiver {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options);
|
|
11
|
+
this._format = "zip";
|
|
12
|
+
this._module = new Zip(options);
|
|
13
|
+
this._supportsDirectory = true;
|
|
14
|
+
this._supportsSymlink = true;
|
|
15
|
+
this._modulePipe();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class TarArchive extends Archiver {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
super(options);
|
|
22
|
+
this._format = "tar";
|
|
23
|
+
this._module = new Tar(options);
|
|
24
|
+
this._supportsDirectory = true;
|
|
25
|
+
this._supportsSymlink = true;
|
|
26
|
+
this._modulePipe();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class JsonArchive extends Archiver {
|
|
31
|
+
constructor(options) {
|
|
32
|
+
super(options);
|
|
33
|
+
this._format = "json";
|
|
34
|
+
this._module = new Json(options);
|
|
35
|
+
this._supportsDirectory = true;
|
|
36
|
+
this._supportsSymlink = true;
|
|
37
|
+
this._modulePipe();
|
|
38
|
+
}
|
|
39
|
+
}
|