mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
Decompress tar.lz tar.bz2 cause exception #741
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 @zhuxb711 on GitHub (Dec 9, 2025).
Originally assigned to: @Copilot on GitHub.
I tried to decompress the
tar.bz2ortar.lzthat created from the SharpCompressBut unfortunately, I got the exception:
Cannot determine compressed stream type. Supported Archive Formats: Zip, Rar, 7Zip, GZip, Tar@zhuxb711 commented on GitHub (Dec 9, 2025):
tar & tar.gz works fine
@adamhathcock commented on GitHub (Dec 9, 2025):
How are you access those formats? FileStreams or another stream?
@zhuxb711 commented on GitHub (Dec 10, 2025):
Use FileStream directly @adamhathcock
@adamhathcock commented on GitHub (Dec 10, 2025):
I think the problem is that bzip2 and lzip only work for forward only streams and there is no archive implementation for either.
GZip works mainly because it's got a single entry.
What is the rest of the code do you have? Try ReaderFactory instead?
@zhuxb711 commented on GitHub (Dec 15, 2025):
But Archive API & Reader API should be both supported as your FORMAT.md indicated
@zhuxb711 commented on GitHub (Dec 15, 2025):
Actually, I use the ReaderFactory to extract the files, but before that I would use the ArchiveFactory to open the file and extract the
TotalUncompressSize. I think even "forward only streams" should be able to calculate theTotalUncompressSize. Any suggestion? An alternative way is to walk the Reader first to getTotalUncompressSizeand walk the Reader again to extract the files. Will it cost to much?@zhuxb711 commented on GitHub (Dec 15, 2025):
Also I need the ArchiveFactory to open the stream first to determine whether the archive is solid or 7zip. Which could not be opened from ReaderFactory. This is how my code works:
@zhuxb711 commented on GitHub (Jan 7, 2026):
@adamhathcock Any suggestion?
@adamhathcock commented on GitHub (Jan 7, 2026):
You have several issues noted that are separate:
ReaderFactory is forward-only and can't get the total size without walking the stream. ArchiveFactory (seekable streams) for zip uses the dictionary. Different formats work differently so I can't answer this.
This was attempted to be addressed here: https://github.com/adamhathcock/sharpcompress/issues/1070
@zhuxb711 commented on GitHub (Jan 7, 2026):
Seems PR 1077 did not provide a way to get IReader without checking
@adamhathcock commented on GitHub (Jan 7, 2026):
The issue says you can do the following without that check:
@zhuxb711 commented on GitHub (Jan 8, 2026):
In my use case, I have to control the extraction process by myself, therefore I would not use the
WriteToDirectorybecause as a developer I would not assume the place that user extracting is local file system@adamhathcock commented on GitHub (Jan 8, 2026):
Please try the latest. I don't know what file you're trying and I think it's some error handling problem that is misleading you