Skip to content

Commit 3fb9e44

Browse files
authored
Follow linked folders (#36)
* Update archiver dependency * Support compressing symlinks on Windows - Add test cases for file and directory symlinks - Add support for compressing file and symlinks on Windows - Test on Windows 10 node 12.16.1 - Test on Ubuntu 18.04 node 12.16.1 both with and without native zip available in path. * Fix EMFILE error, too many open readStream issue.
1 parent bac4990 commit 3fb9e44

File tree

6 files changed

+299
-106
lines changed

6 files changed

+299
-106
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
node_modules/
22
.idea
33
tmp/
4+
test/fixtures/subdir-symlink
5+
test/fixtures/file-symlink.txt
46
test/validArchive.zip
57
test/validARchiveExtract
68
.DS_Store

lib/bestzip.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ const nodeZip = options =>
8282
}
8383
}
8484

85+
function walkDir(fullPath) {
86+
const files = fs.readdirSync(fullPath).map(f => {
87+
const filePath = path.join(fullPath, f);
88+
const stats = fs.statSync(filePath);
89+
if (stats.isDirectory()) {
90+
return walkDir(filePath);
91+
}
92+
return filePath;
93+
});
94+
return files.reduce((acc, cur) => acc.concat(cur), []);
95+
}
96+
8597
function addSource(source, next) {
8698
const fullPath = path.resolve(cwd, source);
8799
const destPath = source;
@@ -90,7 +102,14 @@ const nodeZip = options =>
90102
return next(err);
91103
}
92104
if (stats.isDirectory()) {
93-
archive.directory(fullPath, destPath);
105+
// Walk directory. Works on directories and directory symlinks.
106+
const files = walkDir(fullPath);
107+
files.forEach(f => {
108+
const subPath = f.substring(fullPath.length);
109+
archive.file(f, {
110+
name: destPath + subPath
111+
});
112+
});
94113
} else if (stats.isFile()) {
95114
archive.file(fullPath, { stats: stats, name: destPath });
96115
}

0 commit comments

Comments
 (0)