bower / decompress-zip

Module that decompresses zip files
MIT License
102 stars 76 forks source link

Add `strip` option #13

Closed kevva closed 10 years ago

wibblymat commented 10 years ago

I have a couple of problems here. Firstly you can't use a literal / in anything to do with paths or it won't work on Windows. You need to use path.sep.

Also, I'd like for there to be at least a warning if there are fewer path elements than the strip number. If you have a tree that only goes (for e.g.) two deep and have a strip of 4 then all files will end up in the same place. If two files have the same name one will overwrite the others.

At https://github.com/bower/decompress-zip/blob/master/lib/decompress-zip.js#L89 you could loop through the files and check that they all have a common path prefix of the right length and error out before actually doing any extracting. You could transform the paths at that point too.

I think my preference would actually be that instead of saying strip: 2 you should have to say strip: "angular/dist". Then only files that are in that path will be extracted. But that's kind of a different feature so maybe not.

kevva commented 10 years ago

Whoops, missed path.sep. I'll fix that and add the path depth check. As for using strip: 'some/path' I'm in doubt. I think it's better to stick to the standard (equivalent to --strip-components). That feature should probably go under a different option.

kevva commented 10 years ago

@wibblymat, should it process each file individually and check if options.strip is deeper than file.path? Or maybe you meant that it should check for the deepest path in all files and check it against options.strip?

sindresorhus commented 10 years ago

@wibblymat :arrow_up:

wibblymat commented 10 years ago

@kevva I think I meant that you check up front that each file that is going to be extracted (i.e. after the filter has been applied) is at least as deep as options.strip

kevva commented 10 years ago

@wibblymat, sorry for taking such time. Should be ok now.

kevva commented 10 years ago

ping @wibblymat