Getting a “Cannot Read That as a Zip File” Exception while trying to get a stream from an Inner Zip File (a Zip within another Zip)

前端 未结 1 597
悲&欢浪女
悲&欢浪女 2021-01-13 04:20

In C#, I\'m using the DotNetZip I have a zip called \"innerZip.zip\" which contains some data, and another zip called \"outerZip.zip\" which contains the in

相关标签:
1条回答
  • 2021-01-13 04:25

    This exception occurs because the CrcCalculatorStream stream that OpenReader creates is not seekable, and ZipFile.Read(Stream) tries to seek while opening the zip file.

    The nature of zip compression prevents seeking to a location in the zipped content, the content must be decompressed in order.

    One way around this would be to extract the inner zip file to a MemoryStream and then load that via 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);
    
    0 讨论(0)
提交回复
热议问题