获得一个"无法读取为ZIP文件"异常尝试获取来自内蒙古Zip文件流(另一邮编内的邮编) [英] 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)

查看:778
本文介绍了获得一个"无法读取为ZIP文件"异常尝试获取来自内蒙古Zip文件流(另一邮编内的邮编)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我使用的 DotNetZip
我有一个名为innerZip.zip拉链其中包含了一些数据,
和所谓的outerZip.zip另一拉链包含innerZip。
为什么我做这样的吗?
哦,设置密码时,密码居然适用于被添加到压缩文件,而不是整个档案,使用这种内部/外部组合各个条目,
我可以一通设置为全。内层拉链,因为它是外层的条目

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 innerZip. why am i doing it like this ? well, when setting the password, the password actually applies to individual entries that are added to the archive and not the whole archive, by using this inner/outer combo, I could set a pass to the whole inner zip because it's an entry of the outer one.

但问题是,好,代码胜于普通的话更好:

Problem is, well, code speaks better than normal 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 that exception ? the inner file is a zip file, so i shouldn't be getting that exception right ? is there a way to get around this or I just have to extract the inner one from the outer, and then access it ?

感谢名单提前..

推荐答案

这发生异常,因为 CrcCalculatorStream 流的 OpenReader 创建是不可搜索,而 ZipFile.Read(流)试图寻求在打开zip文件。

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.

zip压缩的性质防止寻求在压缩内容的位置,内容必须是为了解压。

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

单向各地这将是内压缩文件解压缩到一个的MemoryStream 然后加载通过 ZipFile.Read

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);

这篇关于获得一个"无法读取为ZIP文件"异常尝试获取来自内蒙古Zip文件流(另一邮编内的邮编)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆