c# - C++ 和 SharpZipLib

标签 c# c++ zip compression

我对压缩算法不是很精通。

我有一段 C# 代码使用上述库来压缩和解压缩一大块数据。它使用压缩级别 3,但除此之外,它是最基本的实现。

我现在想使用 C++ 对这些数据执行相同的操作。既然是 zip 格式,我们就是在谈论 deflate 算法,对吗?

我假设任何处理 zip 压缩的 c++ 库都使用该算法并且它与 C# 版本兼容是否正确? 3 级压缩是 zip 标准,还是 C# 库独有的东西?

基本上,在寻找库并将其实现到我的代码中时,我需要注意什么?

最佳答案

Since it's a zip format, we are talking about the deflate algorithm, right?

并非所有 .zip 文件都使用 DEFLATE 算法。 ZIP 规范列出了大量它支持的不同压缩方法:

4.4.5 compression method: (2 bytes)

    0 - The file is stored (no compression)
    1 - The file is Shrunk
    2 - The file is Reduced with compression factor 1
    3 - The file is Reduced with compression factor 2
    4 - The file is Reduced with compression factor 3
    5 - The file is Reduced with compression factor 4
    6 - The file is Imploded
    7 - Reserved for Tokenizing compression algorithm
    8 - The file is Deflated
    9 - Enhanced Deflating using Deflate64(tm)
   10 - PKWARE Data Compression Library Imploding (old IBM TERSE)
   11 - Reserved by PKWARE
   12 - File is compressed using BZIP2 algorithm
   13 - Reserved by PKWARE
   14 - LZMA (EFS)
   15 - Reserved by PKWARE
   16 - Reserved by PKWARE
   17 - Reserved by PKWARE
   18 - File is compressed using IBM TERSE (new)
   19 - IBM LZ77 z Architecture (PFS)
   97 - WavPack compressed data
   98 - PPMd version I, Rev 1

Am I correct to assume that any c++ library that deals with zip compression uses that algorithm and that it's compatible with C# version?

虽然 DEFLATE 应该由于其广泛使用而在几乎每个压缩库中实现,但实际上由库作者决定他们支持什么。不过,并非所有库都与 SharpZipLib 兼容,因为不同的程序员对如何最好地组织代码有不同的想法。

Is the level 3 compression a zip standard, or something unique to C# lib?

它是标准的一部分。

    4 - The file is Reduced with compression factor 3

Basically, what do I have to look out for, if anything, when looking for and implementing the library into my code?

确保库支持您要使用的任何压缩方法,确保 API 对您有意义,并尝试找到正在使用的库的基准测试以查看它的速度。例如,如果您需要对 zip 数据执行除读写磁盘以外的操作,请确保库可以写入流或字节缓冲区以通过网络发送。

Link到 ZIP 规范。

关于c# - C++ 和 SharpZipLib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43561651/

相关文章:

c++ - 将从套接字接收到的数据写入 C++ 中的文件

cocoa - 从命令行 Zip - 如何修剪路径元素

c# - 我们应该使用 Azure 服务总线队列内置 CorrelationId 属性还是 UserProperties?

c# - 强制 HttpWebRequest 和 ClientWebSocket 使用 TLS 1.2

c# - 选择 WinForm ListView 项,按 Delete 键 : Trigger Code

c++ - 实现 QRCodeReader (ZXing) 的问题

c++ - 成员如何知道它是在哪个类实例中构造的?

delphi - KaZip for C++Builder2009/Delphi

java - .zip 文件上传 Spring

c# - .NET API 更新包括 ID