您需要了解拥有spanned个压缩文件意味着什么.这意味着一个压缩包被分割成更多的文件.
您链接的文件似乎不是这样的文件:
Archive: Zip.zip
There is no zipfile comment.
End-of-central-directory record:
-------------------------------
Zip archive file size: 646370 (000000000009DCE2h)
Actual end-cent-dir record offset: 646272 (000000000009DC80h)
Expected end-cent-dir record offset: 646272 (000000000009DC80h)
(based on the length of the central directory and its expected offset)
This zipfile constitutes the sole disk of a single-part archive; its
central directory contains 25 entries.
The central directory is 3521 (0000000000000DC1h) bytes long,
and its (expected) offset in bytes from the beginning of the zipfile
is 642751 (000000000009CEBFh).
...
我认为问题在于如何try 读取fileBytes.ToArray()
的文件.data
变量应该是filename,而不是fileBytes.ToArray()
.
如果您查看所提供的关于如何读取压缩文件的示例,您可以从git中看到,在line 53上您会得到ZipFile zip = ZipFile.Read(args[0], options)
,其中args[0]是一个压缩文件名.
下面是完整的GIT示例:
/ ReadZip.cs
//
// ----------------------------------------------------------------------
// Copyright (c) 2006-2009 Microsoft Corporation. All rights reserved.
//
// This example is released under the Microsoft Public License .
// See the license.txt file accompanying this release for
// full details.
//
// ----------------------------------------------------------------------
//
// This simple example utility simply reads a zip archive and extracts
// all elements in it, to the specified target directory.
//
// compile with:
// csc /target:exe /r:Ionic.Zip.dll /out:ReadZip.exe ReadZip.cs
//
// Wed, 29 Mar 2006 14:36
//
using System;
using Ionic.Zip;
namespace Ionic.Zip.Examples
{
public class ReadZip
{
private static void Usage()
{
Console.WriteLine("usage:\n ReadZip2 <zipfile> <unpackdirectory>");
Environment.Exit(1);
}
public static void Main(String[] args)
{
if (args.Length != 2) Usage();
if (!System.IO.File.Exists(args[0]))
{
Console.WriteLine("That zip file does not exist!\n");
Usage();
}
try
{
// Specifying Console.Out here causes diagnostic msgs to be sent to the Console
// In a WinForms or WPF or Web app, you could specify nothing, or an alternate
// TextWriter to capture diagnostic messages.
var options = new ReadOptions { StatusMessageWriter = System.Console.Out };
using (ZipFile zip = ZipFile.Read(args[0], options))
{
// This call to ExtractAll() assumes:
// - none of the entries are password-protected.
// - want to extract all entries to current working directory
// - none of the files in the zip already exist in the directory;
// if they do, the method will throw.
zip.ExtractAll(args[1]);
}
}
catch (System.Exception ex1)
{
System.Console.Error.WriteLine("exception: " + ex1);
}
}
}
}
EDIT-上面发布的压缩文件仍然生成上述错误.我已经查过来源,找出罪魁祸首在哪里:
它认为这是一个基于this read的跨度档案.It tries to read从第二个位置开始的block
的2个字节(转换为16位无符号整数).如果转换后的值为==0xFFFF
,则会将该文件视为包含超过65534个段的跨转文件.可能是压缩文件中存在一些错误,导致DotNetZip失败.