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)

放肆的年华 提交于 2019-12-01 05:20:55

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);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!