From 27dffccdc980fcb5f06d640a16c0bb0456c2a452 Mon Sep 17 00:00:00 2001 From: Ivan Petrovic Date: Fri, 23 Aug 2019 14:24:52 +0200 Subject: [PATCH 1/2] Added option absolute/relative symlinks --- README.md | 1 + lib/decompress-zip.js | 3 ++- lib/extractors.js | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5549c10..a58d68c 100644 --- a/README.md +++ b/README.md @@ -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`) diff --git a/lib/decompress-zip.js b/lib/decompress-zip.js index 466d823..5a672ee 100644 --- a/lib/decompress-zip.js +++ b/lib/decompress-zip.js @@ -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; @@ -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); } } diff --git a/lib/extractors.js b/lib/extractors.js index 5ea9389..cdacb52 100644 --- a/lib/extractors.js +++ b/lib/extractors.js @@ -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}; }); From 2293e5ca156c028383b249d759e826895ad4a7dd Mon Sep 17 00:00:00 2001 From: Ivan Petrovic Date: Thu, 23 Jun 2022 19:24:18 +0200 Subject: [PATCH 2/2] Workpuls to Insightful --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 49613de..417aa5a 100644 --- a/package.json +++ b/package.json @@ -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",