Getting "Can't read this as a zip file" An exception occurred while trying to get a stream from an internal Zip file (Zip in another Zip file)

In C # I use DotNetZip . I have a zip called "innerZip.zip" that contains some data, and another zip called "outerZip.zip" that contains innerZip. why am i doing this? well, when setting a password, the password really applies to individual entries that are added to the archive, and not the entire archive using this internal / external combo. I could set the pass to the entire internal zip code because it is an external record.

The problem is that the code is better than ordinary words:

ZipFile outerZip = ZipFile.Read("outerZip.zip");
outerZip.Password = "VeXe";
Stream innerStream = outerZip["innerZip.zip"].OpenReader();
ZipFile innerZip = ZipFile.Read(innerStream); // I'm getting the exception here.
innerZip["Songs\\IronMaiden"].Extract(tempLocation);

why am i getting this exception? The internal file is a zip file, so shouldn't I get this exception? is there any way around this, or do i just need to extract the internal from the external and then get it?

Thanx in advance ..

+5
source share
1 answer

This exception occurs due to the fact that the stream CrcCalculatorStreamcreated OpenReaderis not searchable, but ZipFile.Read(Stream)tries to search when opening a zip file.

The zip compression nature prevents the search for a location in the compressed content, the contents should be unpacked in order.

One way is to extract the internal zip file to MemoryStream, and then load it through ZipFile.Read.

MemoryStream ms = new MemoryStream();
outerZip["innerZip.zip"].Extract(ms);
ms.Seek(0, SeekOrigin.Begin);
ZipFile innerZip = ZipFile.Read(ms);
innerZip["Songs\\IronMaiden"].Extract(tempLocation);
+6
source

All Articles