Navigation Menu

Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.

Commit

Permalink
#79 Simplify zipping with .bulk(), thanks @ctalkington
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Apr 1, 2014
1 parent 0f26d7e commit 592b737
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions droppy.js
Expand Up @@ -1402,32 +1402,11 @@

archive = archiver(type, {zlib: { level: config.zipLevel }});
archive.on("error", function (error) { log.error(error); });

next = function (currentPath) {
if (currentPath[currentPath.length - 1] !== "/")
archive.file(currentPath, {name: removeFilePath(currentPath)});
else
archive.append("", { name: removeFilePath(currentPath) });
};

archive.on("entry", function () {
if (paths.length)
next(paths.pop());
else
archive.finalize();
});
archive.pipe(res);

utils.walkDirectory(zipPath, true, function (error, foundPaths) {
if (error) log.error(error);
paths = foundPaths.filter(function (s) { return s !== ""; });
if (paths.length === 0) {
archive.append("", { name: "Empty" });
} else {
next(paths.pop());
}

});
archive.bulk([
{ expand: true, cwd: zipPath, src: ["**"], dest: path.basename(zipPath) }
]);
archive.finalize();
} else {
res.statusCode = 404;
res.end();
Expand Down

0 comments on commit 592b737

Please sign in to comment.