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

Strip option causing error #50

Open
BigFunger opened this issue Sep 22, 2015 · 7 comments
Open

Strip option causing error #50

BigFunger opened this issue Sep 22, 2015 · 7 comments

Comments

@BigFunger
Copy link

When i specify a strip option, I get the following error:

[TypeError: Cannot read property 'path' of undefined]

The code that generates the error is below:

var DecompressZip = require('decompress-zip');

var sourcePath = './My-Archive.zip';
var targetPath = './temp';
var unzipper = new DecompressZip(sourcePath);

unzipper.on('error', function (err) {
    console.log('Caught an error');
    console.log(err);
});

unzipper.on('progress', function (fileIndex, fileCount) {
    console.log('Extracted file ' + (fileIndex + 1) + ' of ' + fileCount);
});

unzipper.extract({
  path: targetPath,
  filter: function (file) {
    return file.type !== 'SymbolicLink';
  },
  strip: 1
});

The My-Archive.zip file I am using can be downloaded from here:
https://s3.amazonaws.com/jimtars/My-Archive.zip

The zip file was created using 7zip on Windows 8.1.

@jysperm
Copy link

jysperm commented Oct 9, 2015

Same error, change DecompressZip.prototype.extractFiles in lib/decompress-zip.js from:

files.forEach(function (file) {

To:

files.filter(function(file) {
  return file;
}).forEach(function (file) {

Will resolve this problem.

@darkyen
Copy link

darkyen commented Feb 28, 2016

Can this be merged ?

@alexcroox
Copy link

+1 for merge, fixed my error

@hintdesk
Copy link

Please merge and release new version in npm.

@swoopedj
Copy link

swoopedj commented Nov 8, 2017

+1 for merge, fixed my error as well

@boid-com
Copy link

merge this please

@pento
Copy link

pento commented Jun 2, 2018

For folks running into this, the cause is that this map() doesn't return anything if file.type === 'Directory', which leaves the entry in files array as undefined.

#51 isn't the correct fix for this, it'd be better to move the return outside of the if() in the map() callback.

You can work around it by adding this filter to your extract() call:

unzipper.extract( {
	path: '/some/path',
	strip: 1,
	filter: ( file ) => file.type !== 'Directory',
} );

This seems to work for me, but it might fail under some circumstances. Off the top of my head, I guess it means that empty directories won't be extracted, and there are probably other side effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

8 participants