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

Cannot add empty directory structures to output. #412

Open
noisysoil opened this issue Jan 27, 2022 · 4 comments
Open

Cannot add empty directory structures to output. #412

noisysoil opened this issue Jan 27, 2022 · 4 comments
Labels
enhancement New feature or request for archiving Issue on archiving, compression or encryption for extraction Issue on extraction, decompression or decryption good first issue Good for newcomers help wanted Extra attention is needed

Comments

@noisysoil
Copy link

Describe the bug
When an archive structure in memory contains empty directories such as:
empty-dir1/empty-dir2/empty-dir3
...then when adding these to an archive, they do not appear in the final output.

To Reproduce
Create a .7z file with an empty directory structure; taking the example above ('empty-dir1/empty-dir2/empty-dir3'):
7z a empty-dir-test.7z empty-dir1

Then recompress the test file with py7zr:

            compression_filters = [{'id': py7zr.FILTER_LZMA2, 'preset': 9}]
            with py7zr.SevenZipFile(f"test-output.7z", mode="w",
                                    filters=compression_filters) as target:
                with py7zr.SevenZipFile(f"empty-dir-test.7z", mode='r') as source:
                    target.writed(source.readall())

Expected behavior
Directory structure should be preserved.

Environment (please complete the following information):

  • OS: Kubuntu Linux 21.10
  • Python 3.9
  • py7zr version: 0.17.3

Test data(please attach in the report):
An archive structure containing an empty directory (see 'To reproduce').

@miurahr miurahr added the enhancement New feature or request label Jan 27, 2022
@miurahr miurahr added help wanted Extra attention is needed good first issue Good for newcomers for extraction Issue on extraction, decompression or decryption for archiving Issue on archiving, compression or encryption labels Apr 18, 2022
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@miurahr
Copy link
Owner

miurahr commented Aug 3, 2022

readall method returns Dict[filename: str, object: io.BytesIO] that cannot return a directory as entry. Are there any idea to express directory?

@Ru13en
Copy link

Ru13en commented Sep 7, 2022

Hi,
There is a way to write empty directories and maintain their structure:

import py7zr
import tempfile
with py7zr.SevenZipFile(f"test-output.7z", mode="w") as target:
    target.write(tempfile.mkdtemp(), "empty-dir1/empty-dir2/empty-dir3")

It should be explained in the docs.

@github-actions
Copy link

github-actions bot commented Dec 7, 2022

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request for archiving Issue on archiving, compression or encryption for extraction Issue on extraction, decompression or decryption good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants