Feature: exclude leading directory when extracting #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request aims to add a new feature to unzipper. If an archive to be extracted only contains one single directory in its root, unzipper can now choose to only extract the content of this single directory and not include the directory itself in the extraction.
The feature is controlled by a checkbox added to the HTML.
I got this idea when trying to deploy WordPress on a new website. After extracting the zip file downloaded from wordpress.org I got a wordpress/ directory in my website root instead of the WordPress files and folders, which is not what I intended.
I tried many solutions to this problem and finally decided on the following:
It may seem like a better idea to extract each file from an archive directly to the destination folder, thereby not needing a tmpdir. But the only way I found to do this was by iterating over the archive files and using
copy("zip://archive.zip#path/to/file.txt")
. And this solution has serious performance problems with larger archives. Archives that can normally be extracted will instead be cancelled by the PHP max_execution_time.The implemented solution is also easy to incorporate in any future additions to supported archive formats.
Feedback is welcome.