miurahr / py7zr

7zip in python3 with ZStandard, PPMd, LZMA2, LZMA1, Delta, BCJ, BZip2, and Deflate compressions, and AES encryption.

Home Page:https://pypi.org/project/py7zr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot add empty directory structures to output.

noisysoil opened this issue · comments

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').

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

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

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.

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