mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
Unpopulated ArchiveEntry.Key from unix tar.gz #93
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 @FelixTurtur on GitHub (Mar 3, 2016).
Hi,
We've come across an issue when trying to extract tar.gz archives created in ubuntu because the initial archive entry has an empty Key property (in fact most fields, Crc, ArchivedTime, Size, filePart.FilePartName.. are empty) and we get a null reference exception when trying to extract it.
I was looking at issue #128 which seemed similar, but these not being git archives, the fix doesn't solve this issue. I have noted that extracting and recreating the gz archive in windows via 7z results in an tar.gz archive which can then be opened by SharpCompress, so I assume the issue relates to them specifically being unix-created archives.
I've attached one which I've created and am unable to open. I've tried debugging to see if anything obvious jumps out, but I'm afraid I don't really know much about the intricacies of archive files to understand what's amiss.
archive.tar.gz
State of the GZipArchiveEntry:

@adamhathcock commented on GitHub (Mar 30, 2016):
I just ran your archive with the latest code and it seemed fine. I haven't published a new version with the issue you referred to so maybe that's your problem?
@FelixTurtur commented on GitHub (Mar 30, 2016):
I can't open it using 11.5 and built latest code at the time of writing the issue (to check the issue-fix I mentioned), which also didn't help. Just opening it using
ArchiveFactory.Open(filePath)results in a single entry with null Key, as above. Are tar.gz archives supposed to be opened another way?@adamhathcock commented on GitHub (Mar 30, 2016):
I tested with
ReaderFactoryI'll try your way@adamhathcock commented on GitHub (Mar 30, 2016):
Oh wait. I see the issue.
ArchiveFactorydoesn't support doing tar.gz because it's random access.If you want to read entries out of a tar.gz without ungzipping the tar first then you need to use
ReaderFactory@adamhathcock commented on GitHub (Mar 30, 2016):
A GZipArchive will only ever have one entry and having a filename is optional. GZip has a few headers but it's mostly lipstick on the deflate algorithm to be a single compressed file. Tars have actual entries. This is why this behavior is weird.
@FelixTurtur commented on GitHub (Mar 31, 2016):
Thanks, I'm using
ReaderFactorynow without any issue.@lsantos124 commented on GitHub (Feb 21, 2018):
I am using ReaderFactory to try to decompress a Unix-created .gz archive and it does not seem to work. It seems to be the same issue as Felix's issue. I noticed that when I uncompressed it through 7zip and then rezipped it into a .gz file on Windows, that it was able to be unzipped. I have attached the windows created .gz and the unix created .gz.
windows_created.bson.gz
unix_created.bson.gz
I am using the following code:
The unix_created .gz file fails at the archive.WriteToDirectory( .. ) line. Below shows that the unix_created archive shows no key while the windows one does.
Any help on this issue would be great.