mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
ZIP DeflateStream inside ZIP #535
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @i2um1 on GitHub (Aug 18, 2022).
Hi,
I have the following zip structure:
But the following code does not work:
Exception:
The following code has more interesting behavior without exceptions:
Console Output:
I know it's stupid to have a zip file inside a zip file. But is it possible somehow to make it work?
@Erior commented on GitHub (Aug 25, 2022):
The output from a deflated stream is not seekable, you can not use the ZipArchive call directly, you would need to copy to temporary file or MemoryStream to make it seekable.
If the internal zip was in "stored" mode, you would end up with an error regarding ReadOnlySubStream instead of deflate stream, same solution would apply.
ReaderFactory does not use the CentralArchive information at the end of the archive and tries to read from the start.
Archive: file.zip
Zip file size: 5600 bytes, number of entries: 1
-rw-r--r-- 3.0 unx 5428 bx stor 22-Aug-25 21:57 another.zip
1 file, 5428 bytes uncompressed, 5428 bytes compressed: 0.0%
Archive: another.zip
Zip file size: 5428 bytes, number of entries: 4
drwxr-xr-x 3.0 unx 0 bx stor 22-Aug-25 21:57 7707/
-rw-r--r-- 3.0 unx 4096 bx defN 22-Aug-25 21:57 7707/file1.txt
-rw-r--r-- 3.0 unx 4096 bx defN 22-Aug-25 21:57 7707/file2.txt
-rw-r--r-- 3.0 unx 4096 bx defN 22-Aug-25 21:57 7707/file3.txt
4 files, 12288 bytes uncompressed, 4800 bytes compressed: 60.9%
Output from code with ReaderFactory
7707/
7707/file1.txt
7707/file2.txt
7707/file3.txt
This works then because we do not try to read the end of the file and then jump back to the start on a stream that does not handle Seek or setting position.
@i2um1 commented on GitHub (Aug 26, 2022):
Oh, I see, thank you for the description.