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

Added option absolute/relative symlinks #68

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Returns an EventEmitter with two possible events - `error` on an error, and `ext
**Options**
- **path** *String* - Path to extract into (default `.`)
- **follow** *Boolean* - If true, rather than create stored symlinks as symlinks make a shallow copy of the target instead (default `false`)
- **absolute** *Boolean* - If false, all symlinks will be exported the same way they were created, by default aboslut symlinks will be created (default `true`)
- **filter** *Function* - A function that will be called once for each file in the archive. It takes one argument which is an object containing details of the file. Return true for any file that you want to extract, and false otherwise. (default `null`)
- **strip** *Number* - Remove leading folders in the path structure. Equivalent to `--strip-components` for tar.
- **restrict** *Boolean* - If true, will restrict files from being created outside `options.path`. Setting to `false` has significant security [implications](https://snyk.io/research/zip-slip-vulnerability) if you are extracting untrusted data. (default `true`)
Expand Down
3 changes: 2 additions & 1 deletion lib/decompress-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ DecompressZip.prototype.extract = function (options) {
options.path = options.path || process.cwd();
options.filter = options.filter || null;
options.follow = !!options.follow;
options.absolute = options.absolute !== false;
options.strip = +options.strip || 0;
options.restrict = options.restrict !== false;

Expand Down Expand Up @@ -313,7 +314,7 @@ DecompressZip.prototype.extractFile = function (file, options) {
if (options.follow) {
return extractors.copy(file, destination, this, options.path);
} else {
return extractors.symlink(file, destination, this, options.path);
return extractors.symlink(file, destination, this, options.path, options.absolute);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/extractors.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ var extractors = {
return {deflated: file.path};
});
},
symlink: function (file, destination, zip, basePath) {
symlink: function (file, destination, zip, basePath, absolute) {
var parent = path.dirname(destination);
return mkdir(parent, zip.dirCache)
.then(function () {
return getLinkLocation(file, destination, zip, basePath);
})
.then(function (linkTo) {
return symlink(path.resolve(parent, linkTo), destination)
return symlink(absolute? path.resolve(parent, linkTo) : linkTo, destination)
.then(function () {
return {symlink: file.path, linkTo: linkTo};
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "decompress-zip",
"name": "@insightfulio/decompress-zip",
"version": "0.3.2",
"description": "Extract files from a ZIP archive",
"main": "lib/decompress-zip.js",
Expand Down