gpt4 book ai didi

c# - 异常: EOF in Header occuring while extracting zip from isolated storage

转载 作者:行者123 更新时间:2023-12-02 10:57:32 55 4
gpt4 key购买 nike

我使用流编写器在名为 temp.zip 的独立存储中生成了一个 zip,并在流中返回其字节以进行提取。请找到以下代码

stream = LoadZipFromLocalFolder(filename);
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var zipStream = new ZipInputStream(stream))
{
ZipEntry entry;
//EOF in header occuring on below line
while ((entry = zipStream.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(entry.Name);
string fileName = Path.GetFileName(entry.Name);

if (!string.IsNullOrEmpty(fileName))
{
if (!isoStore.DirectoryExists(directoryName))
{
isoStore.CreateDirectory(directoryName);
}

string fileFullPath = Path.Combine(directoryName, fileName);
Debug.WriteLine(fileFullPath);
using (var streamWriter = new BinaryWriter(new IsolatedStorageFileStream(fileFullPath, FileMode.Create, FileAccess.Write, FileShare.Write, isoStore)))
{
var buffer = new byte[2048];
int size;
while ((size = zipStream.Read(buffer, 0, buffer.Length)) > 0)
{
streamWriter.Write(buffer, 0, size);
}
streamWriter.Close();
streamWriter.Dispose();
}
}
}
}
}

当我创建 temp.zip 时,它具有读写共享权限,并且我尝试手动解压缩,然后它被正确提取而不会导致任何错误,但在代码显示错误 HEADER 中的 EOF

请帮忙..

谢谢

最佳答案

我通过使用简单的代码解决了 header 中的EOF,如下所示:

Stream.Position =0;

希望它对某人有所帮助。

谢谢。

关于c# - 异常: EOF in Header occuring while extracting zip from isolated storage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26623145/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com