Our current implementation on our ASP.net website doesn’t support Zip64 which it needs to, so we’re moving from System.IO.Compression
over to DotNetZip
:
https://github.com/DinoChiesa/DotNetZip
This small archive:
https://github.com/DinoChiesa/DotNetZip/files/10184907/Zip.zip
Throws the error:
Spanned archives with more than 65534 segments are not supported at this time.
The code sample simply attempts to open the Zip file:
using (var data = new MemoryStream(fileBytes.ToArray()))
{
using (var archive = Ionic.Zip.ZipFile.Read(data))
{
....
}
I’m a little unsure what the issue is here, is there an easy workaround or is there a better altnerative library?
2
Answers
You need to understand what does mean to have spanned zip file. That means that a zip is split into more files.
The file you have linked appears not to be such file:
I think the problem is how you try to read the file with
fileBytes.ToArray()
. Thedata
variable should be a filename and notfileBytes.ToArray()
.If you look at the provided example, on how to read zip file, from the git you can see that on line 53 you get
ZipFile zip = ZipFile.Read(args[0], options)
, where args[0] is a zip filename.Here is the complete example form the git:
EDIT – the above posted zip file still generates the above error. I have checked the source to find out where is the culprit:
It thinks it is a spanned archive based on this read. It tries to read a 2 bytes (that are converted to 16-bit unsigned integer ) from the
block
starting at 2nd position. If the converted value is==0xFFFF
then it considers the file as spanning file with more than 65534 segments. Probably there is some bug in the packing of the zip file which makes the DotNetZip fail.There is the SharpZipLib nuget package you can use as an alternative.
The code below runs successfully with input the file you posted
Output
P.S. I have worked with both libraries in the past and I have found that DotNetZip is easier to work with, but for this case only SharpZipLib works :).