bestzip 4.0.2 → 4.0.4
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/README.md +1 -1
- package/lib/nodezip.js +22 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ await bestZip({
|
|
|
75
75
|
### API Options
|
|
76
76
|
|
|
77
77
|
* `source`: Path or paths to files and folders to include in the zip file. String or Array of Strings.
|
|
78
|
-
* `destination`: Path to generated .zip file.
|
|
78
|
+
* `destination`: Path to generated .zip file. bestzip excludes the destination from the archive, so it is safe to write it inside a folder that is also being zipped.
|
|
79
79
|
* `cwd`: Set the Current Working Directory that source and destination paths are relative to. Defaults to `process.cwd()`
|
|
80
80
|
* `level`: Level of compression, as with the native `zip` command. An integer from 0 (store, no compression) to 9 (maximum compression). Defaults to each implementation's own default when unset.
|
|
81
81
|
* `followSymLinks`: Follow symbolic links and include the contents of their targets in the zip file. When set to `true` or `false` the preference is honored and no warning is printed. When left unset, symbolic links are **not** followed and a warning is printed whenever symlinks are detected (see [Symbolic links](#symbolic-links)).
|
package/lib/nodezip.js
CHANGED
|
@@ -14,31 +14,25 @@ export async function nodeZip(options) {
|
|
|
14
14
|
const followSymLinks = options.followSymLinks === true;
|
|
15
15
|
const trackSymLinks = typeof options.followSymLinks === "undefined";
|
|
16
16
|
const symlinks = [];
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
"w"
|
|
20
|
-
);
|
|
17
|
+
const destination = path.resolve(cwd, options.destination);
|
|
18
|
+
const outputFile = await fsp.open(destination, "w");
|
|
21
19
|
const output = outputFile.createWriteStream();
|
|
22
20
|
const archive = new ZipArchive({
|
|
23
21
|
zlib: { level: options.level },
|
|
24
22
|
});
|
|
25
23
|
|
|
26
|
-
output.on("close", async () => {
|
|
27
|
-
await outputFile.close();
|
|
28
|
-
resolvePromise();
|
|
29
|
-
});
|
|
30
|
-
archive.on("error", (err) => rejectPromise(err));
|
|
31
|
-
archive.on("warning", (err) => console.warn(err && err.message));
|
|
32
|
-
|
|
33
|
-
archive.pipe(output);
|
|
34
|
-
|
|
35
|
-
let resolvePromise;
|
|
36
24
|
let rejectPromise;
|
|
37
25
|
const promise = new Promise((resolve, reject) => {
|
|
38
|
-
resolvePromise = resolve;
|
|
39
26
|
rejectPromise = reject;
|
|
27
|
+
output.on("close", resolve);
|
|
28
|
+
// output (createWriteStream) closing automatically closes outputFile
|
|
29
|
+
archive.on("error", reject);
|
|
40
30
|
});
|
|
41
31
|
|
|
32
|
+
archive.on("warning", (err) => console.warn(err && err.message));
|
|
33
|
+
|
|
34
|
+
archive.pipe(output);
|
|
35
|
+
|
|
42
36
|
async function addSource(source) {
|
|
43
37
|
const fullPath = path.resolve(cwd, source);
|
|
44
38
|
const destPath = source;
|
|
@@ -49,6 +43,19 @@ export async function nodeZip(options) {
|
|
|
49
43
|
// target contents archived, matching the native zip implementation).
|
|
50
44
|
const entries = await walkTree(fullPath, followSymLinks);
|
|
51
45
|
for (const entry of entries) {
|
|
46
|
+
// The archive was created (and truncated) above, so a source that
|
|
47
|
+
// reaches it — directly, or through a directory glob — would otherwise
|
|
48
|
+
// archive a partial copy of the archive itself. walkTree yields absolute
|
|
49
|
+
// normalized paths, so this compares directly.
|
|
50
|
+
//
|
|
51
|
+
// Known limit: neither implementation compares file identity, only paths,
|
|
52
|
+
// so a destination accessed via a symlinked parent directory still
|
|
53
|
+
// matches itself when the walk reaches the same file by its real path.
|
|
54
|
+
// That needs followSymLinks: true plus an overlapping symlink, and it affects
|
|
55
|
+
// nativeZip identically, so it is left alone rather than diverging here.
|
|
56
|
+
if (entry.path === destination) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
52
59
|
const archiveName = destPath + entry.path.substring(fullPath.length);
|
|
53
60
|
if (entry.stats.isSymbolicLink()) {
|
|
54
61
|
// Storing a link: keep the raw link target and record it for the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bestzip",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Uses OS zip command if available (for better performance and speed) or node.js version if there is no system command available. Can be called via node or command line.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/bestzip.js",
|