mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
Unzip file using IArchieve #391
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 @ArunaVignesh on GitHub (Mar 31, 2020).
Hi
i am developing mobile app. i cant unzip some of the zip file using IArchieve.
I got the follwing exception
SharpCompress cannot currently read non-seekable Zip Streams with encrypted data th
at has been written in a non-seekable manner
If i am using ZipArchieve, it can open and read the file. If i want to write the zipEntry , zipentry.writetoDirectory method is missing. i got the answer that , it will not support on moble when google. What shall i do for write to directory.
i didnt get exception for all the zipfiles
SharpCompress.Archives.IArchive zipfiles = SharpCompress.Archives.ArchiveFactory.Open(zipFileName as string, options);
string unzipPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "tmp", "unzip");
DirectoryInfo dirInfo = new DirectoryInfo(unzipPath);
foreach (var e in zipfiles.Entries)
{
if (!e.IsDirectory)
{
SharpCompress.Archives.IArchiveEntryExtensions.WriteToDirectory(e, dirInfo.ToString(), new SharpCompress.Common.ExtractionOptions() { ExtractFullPath = true, Overwrite = true });
break;
}
}
@adamhathcock commented on GitHub (Apr 3, 2020):
SharpCompress cannot currently read non-seekable Zip Streams with encrypted data th at has been written in a non-seekable mannerIs the error you get when using the Reader interface with a zip file that isn't formatted for non-seekable reading. Zip files have to be written with a trailer header on file entries and other information in the file header. This is data is optional in the spec so not all compressors do it.
@ArunaVignesh commented on GitHub (Apr 6, 2020):
Is there any other way to solve optional header data problem?
Is there any code changes need?
@adamhathcock commented on GitHub (Apr 6, 2020):
Your zip files have to be written with the trailer header. Sharpcompress will do this with the Writer interface but it's all dependent upon the app that writes the zips. Otherwise, you'll just have to use the Archive interface.
The downside is that you have to have the complete file available to read the dictionary at the end of the zip to know about all the entries. Seeking to the correct file is fast though if the complete file is available.
@ArunaVignesh commented on GitHub (Apr 15, 2020):
Is there any sample to convert the received non seekable zip file to seekable zip file(to add about all the entries at the end of zip file)?
In future, sharpcompress have any idea of support to write the non seekable encrypted zip file ?
@adamhathcock commented on GitHub (Apr 15, 2020):
You can unzip with the Archive interface and create with the Writer interface. That will always make seekable archives. Examples can be found in the Tests
@ArunaVignesh commented on GitHub (Apr 17, 2020):
Thank you for your suggestion.
I checked your source and find out the solution. Your source working properly for the following changes.
Change need files for the following folder
src/SharpCompress/Common/Zip/
1.ZipHeaderFactry.cs
Line 134 changed1 check
FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor)
->
!FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor)
2.ZipFilePart.cs
Line 136 Added 1 check
&& !FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor))
Reason is non-Seekable zip with encrypted file also supported in your following program ZipFilePart.cs file. But now the situation is your source is not working because ZipHeaderFactry.cs file line 134 throw exception and ZipFilePart.cs Line136 also throw exception . So this is not running further steps here after.
May be many changes in new zip format for the following. We expect latest update your SharpCompress also. Newly added strong encryption (bit6, bit13) and etc.,
https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
I have attached the changed file also. please refer..
can you add this changes in nuget packages...
FileList.zip
@adamhathcock commented on GitHub (Apr 17, 2020):
That’s not the best way to share code and submit fixes. Please read up on how to use GitHub and submit a pull request to this repository if you’ve got fixes to share. Thanks.