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

feat: ZipArchive::root_dir and ZipArchive::extract_unwrapped_root_dir #304

Merged
merged 5 commits into from
Mar 17, 2025

Conversation

WilliamVenner
Copy link
Contributor

This PR implements the concept of a "root directory" in the Zip archive in the context of extraction.

It's very typical to find Zip archives that consist of a single, sole, top-level, root directory containing the rest of the archive's entries. In some cases this might be something the developer wants to "unwrap" when extracting.

Example

Imagine a Zip archive with the following structure:

root/file1.txt
root/file2.txt
root/sub/file3.txt
root/sub/subsub/file4.txt

If the archive is extracted to foo using ZipArchive::extract, the resulting directory structure will be:

foo/root/file1.txt
foo/root/file2.txt
foo/root/sub/file3.txt
foo/root/sub/subsub/file4.txt

If the archive is extracted to foo using ZipArchive::extract_unwrapped_root_dir, the resulting directory structure will be:

foo/file1.txt
foo/file2.txt
foo/sub/file3.txt
foo/sub/subsub/file4.txt

Example - No Root Directory

Imagine a Zip archive with the following structure:

root/file1.txt
root/file2.txt
root/sub/file3.txt
root/sub/subsub/file4.txt
other/file5.txt

Due to the presence of the other directory, ZipArchive::extract_unwrapped_root_dir will extract this in the same fashion as ZipArchive::extract as there is now no "root directory."

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@Pr0methean Pr0methean enabled auto-merge March 16, 2025 16:19
auto-merge was automatically disabled March 16, 2025 20:13

Head branch was pushed to by a user without write access

@WilliamVenner WilliamVenner force-pushed the feat/root-dir-extraction branch from d45137b to 67724b1 Compare March 16, 2025 20:13
@WilliamVenner
Copy link
Contributor Author

I think that should do it.

@Pr0methean Pr0methean added this pull request to the merge queue Mar 17, 2025
Merged via the queue into zip-rs:master with commit fbf24fc Mar 17, 2025
39 checks passed
@Pr0methean Pr0methean mentioned this pull request Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants