ZIP64压缩扩展的兼容性问题
一、ZIP压缩的两种规范
zip64 格式是标准 zip 格式的扩展,实际上消除了 zip 存档中文件大小和数量的限制。
每种格式允许的最大值总结如下:
Standard Format | Zip64 Format | |
---|---|---|
Number of Files Inside an Archive | 65,535 | 2^64 - 1 |
Size of a File Inside an Archive [bytes] | 4,294,967,295 | 2^64 - 1 |
Size of an Archive [bytes] | 4,294,967,295 | 2^64 - 1 |
Number of Segments in a Segmented Archive | 999 (spanning) 65,535 (splitting) | 4,294,967,295 - 1 |
Central Directory Size [bytes] | 4,294,967,295 | 2^64 - 1 |
二、.NET提供的ZIP压缩能力
.NET提供了以下几个类来完成压缩功能,但是没有找到ZIP64的选项;
ZipFile
ZipArchive
ZipArchiveEntry
DeflateStream
GZipStream
三、DotNetZip提供的压缩能力
DotNetZip 是一个快速、免费的类库和工具集,用于处理 zip 文件。使用 VB、C# 或任何 .NET 语言轻松创建、提取或更新 zip 文件。
DotNetZip提供了Zip64Option来控制压缩的格式;默认情况下使用Never,即不使用ZIP64扩展;
public enum Zip64Option
{
//
// Summary:
// The default behavior, which is "Never". (For COM clients, this is a 0 (zero).)
Default = 0,
//
// Summary:
// Do not use ZIP64 extensions when writing zip archives. (For COM clients, this
// is a 0 (zero).)
Never = 0,
//
// Summary:
// Use ZIP64 extensions when writing zip archives, as necessary. For example, when
// a single entry exceeds 0xFFFFFFFF in size, or when the archive as a whole exceeds
// 0xFFFFFFFF in size, or when there are more than 65535 entries in an archive.
// (For COM clients, this is a 1.)
AsNecessary = 1,
//
// Summary:
// Always use ZIP64 extensions when writing zip archives, even when unnecessary.
// (For COM clients, this is a 2.)
Always = 2
}
我们可以通过以下方式来生成zip压缩文件
public void ZIPContents(IDictionary<string, string> entrys, string zipFileName)
{
ZipFile zipfile = new ZipFile(zipFileName);
zipfile.UseZip64WhenSaving = Zip64Option.AsNecessary;
foreach (var entry in entrys)
{
zipfile.AddEntry(entry.Key, entry.Value);
}
zipfile.Save();
}
四、ZIP64的兼容问题
ZIP64作为一个后来的扩展,虽然有很长的时间了,但是还是有一些操作系统或者开发语言的类库都不支持,从而会造成兼容性问题,最好是Zip64Option.AsNecessary选项,只有在必要的时候自动使用ZIP64位扩展;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2021-03-21 使用normalizer优化keyword字段的查询