-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Writing an empty file to an archive produces unexpected or wrong results #398
Comments
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 |
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 |
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 |
I encountered the exact same bugs in 0.20.6, both shifted name when the there is empty file. and the "ValueError: read of closed file" exception bug when using zip_file = zipfile.ZipFile('/path/to/zipfile.zip', 'r')
archive = py7zr.SevenZipFile('/path/to/new.7z', 'w')
for file_info in zip_file.infolist():
fname = file_info.filename
if fname.endswith('/'):
continue
z1 = zip_file.open(fname)
archive.writef(z1, fname)
z1.close()
archive.close() |
I found one way workaround for compressing empty file is using a |
Describe the bug
If one tries to write an empty file (more specifically, a 0 byte file) to a SevenZipFile, different write methods produce different (and sometimes wrong) results. To be specific, when writing an empty file:
write(path_to_file, ...)
, the file is properly added to the archive, and the archive is a valid 7z file; This is the expected behaviour.writestr(b"", ...)
, the file is added as an empty directory, and all subsequent files have shifted file infos and data (as if the 0-byte file entry is missing, but the data is not; see below for a visual explanation); The archive is a valid 7z file, but it contains bad data.writef(stream, ...)
, an exception is raised (see below for stack trace)Related issue
#343 also tries to add an empty file that produces unexpected results, and is possibly related.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Consistent behaviour, like the
write
method, and no exceptions.Environment:
Test data(please attach in the report):
Here are some example files:
test data.zip
Additional context
7z.exe listing of the expected behaviour (
write
):7z.exe listing of the
writestr
method: Observe the "shifted down" sizes for files,c.txt
directory, and the missing 22-byte data that was ine.txt
.e.txt
now contains the data that should be stored ind.txt
, andd.txt
contains thec.txt
empty data.Stack trace for the
writef
method:The text was updated successfully, but these errors were encountered: