Ionic.Zip.ZipException: Cannot read that as a ZipFile
ahmadfraz1992 opened this issue · 2 comments
We are having issue on opening the zip file from .netstandard library project.
We are working on xamarin.Android
Current version
Here is the code snippet.
Dictionary<string, byte[]> files = new Dictionary<string, byte[]>();
string keyname = "";
try
{
using (var strm = new MemoryStream(byteArray))
using (ZipFile z = ZipFile.Read(strm))
{
foreach (ZipEntry zEntry in z)
{
MemoryStream tempS = new MemoryStream();
zEntry.ExtractWithPassword(tempS, password);
files.Add(zEntry.FileName, tempS.ToArray());
}
}
}
catch (Exception ex)
{
}
When we try reading the ZipFile it generates an error. Following is the stack trace of exception.
at Ionic.Zip.ZipFile.ReadIntoInstance (Ionic.Zip.ZipFile zf) [0x00170] in C:\projects\dotnetzip-semverd\src\Zip.Shared\ZipFile.Read.cs:660
at Ionic.Zip.ZipFile.Read (System.IO.Stream zipStream, System.IO.TextWriter statusMessageWriter, System.Text.Encoding encoding, System.EventHandler`1[TEventArgs] readProgress) [0x00072] in C:\projects\dotnetzip-semverd\src\Zip.Shared\ZipFile.Read.cs:543
at Ionic.Zip.ZipFile.Read (System.IO.Stream zipStream) [0x00000] in C:\projects\dotnetzip-semverd\src\Zip.Shared\ZipFile.Read.cs:414
And the stack trace of inner exception is
at Ionic.Zip.SharedUtilities.StringFromBuffer (System.Byte[] buf, System.Text.Encoding encoding) [0x00000] in C:\projects\dotnetzip-semverd\src\Zip.Shared\Shared.cs:252
at Ionic.Zip.ZipEntry.ReadDirEntry (Ionic.Zip.ZipFile zf, System.Collections.Generic.Dictionary`2[TKey,TValue] previouslySeen) [0x0048d] in C:\projects\dotnetzip-semverd\src\Zip.Shared\ZipDirEntry.cs:277
at Ionic.Zip.ZipFile.ReadCentralDirectory (Ionic.Zip.ZipFile zf) [0x00089] in C:\projects\dotnetzip-semverd\src\Zip.Shared\ZipFile.Read.cs:724
Please let me know what i am doing wrong
Is this the library bug.
Do you have sample data you can include with this issue? For instance do you have a sample file or a dump of the byteArray
that you are reading from? The exception is occurring when attempting to read the file name from the buffer and my guess it is related to the text encoding of the file name. Without sample data that reproduces the issue, it will be very difficult to track this down.
I tried.
……
memoryStream.Seek(0, SeekOrigin.Begin);
ZipRead(memoryStream).ExtractAll(....) ```
……
It's working fine now, but I don't know why it's doing this.