Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utility method for adding symlinks #34

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added error checking and actually uses options object
additional validation is made against the options mode to see if the `mode` parameter to see if it actually specifies a symlink
  • Loading branch information
shortercode committed Nov 28, 2017
commit 7257a5e71984ae2d93946589ee156c659b82fbd7
19 changes: 14 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,25 @@ ZipFile.prototype.addFile = function(realPath, metadataPath, options) {
});
};

ZipFile.prototype.addSymlink = function(realPath, metadataPath, options) {
ZipFile.prototype.addSymlink = function(realPath, metadataPath, options, callback) {
var self = this;
fs.lstat(realPath, function(err, stats) {
if (err)
return callback(err);
if (!stats.isSymbolicLink())
return callback(new Error("\"" + readPath + "\" is not a symbolic link"));
fs.readlink(realPath, { encoding: "utf8" }, function (err, linkString) {
if (err)
return callback(err);
var buffer = Buffer.from(linkString);
var options = {
mode: stats.mode,
compress: false
};
if (!options) options = {};
if (!options.mode) options.mode = stats.mode;
else if (options.mode >>> 28 !== 10)
return new Error("\"" + options.mode + "\" gives the wrong entry type for a symbolic link");
if (!options.compress) options.compress = false;

self.addBuffer(buffer, metadataPath, options);
callback();
})
});
};
Expand Down