最好的 .NET Framework 压缩类?

发布于 2024-08-31 13:49:52 字数 324 浏览 2 评论 0原文

是的,我知道 GZipStream 或 DeflateStream 是 .NET Framework 中处理压缩/解压缩的常见工具。

我希望在我的程序中具有压缩/解压缩功能,但是

  1. 我希望使用 .NET Framework C# 功能,而不是第 3 方开源软件。由于程序中的版权限制,我无法使用。

  2. GZipStream 和 DeflateStream 不太好。例如,GZipStream 将文件压缩到 480KB,而 7Zip 将同一文件压缩到 57KB。

微软还有其他好的压缩方法吗???

谢谢

Yes, I know GZipStream or DeflateStream is the common ones in .NET Framework which handle compression/decompression.

I wish to have compress/decompress functions in my program, but

  1. I wish a .NET Framework C# one, not a 3rd party open source. I can't use because of those copyright restrictions in my program.

  2. GZipStream and DeflateStream are not so good. for e.g., GZipStream compress a file to 480KB while 7Zip compress the same file to the size of 57KB.

Does Microsoft have other good compression methods???

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

趁年轻赶紧闹 2024-09-07 13:49:52

GZipStream 和 DeflateStream 专门用于压缩,而不是用于存储的一般文件压缩。

除了这些类之外,.NET 中并未内置压缩。如果你想要高质量的压缩,你将不得不去第三方库。查看 http://www.7-zip.org/sdk.html 获取开源 7zip 库。

GZipStream and DeflateStream are specifically intended for compressed streams, not general compression of files for storage.

Other than those classes, compression is not built into .NET. If you want high-quality compression you will have to go to a third party library. Check out http://www.7-zip.org/sdk.html for an open-source 7zip library.

讽刺将军 2024-09-07 13:49:52

7zip 有一个托管包装器。该许可证是 LGPL,因此您可以在闭源项目中使用它。我不知道这是否符合您的许可证要求,因为您没有说明。

http://sevenzipsharp.codeplex.com/

There is a managed wrapper for 7zip. The license is LGPL so you can use it in closed source projects. I do not know if this fits your license requirements as you did not state them.

http://sevenzipsharp.codeplex.com/

源来凯始玺欢你 2024-09-07 13:49:52

我没有任何有关压缩率的统计数据,但我一直在使用 SharpZipLib图书馆多年来取得了巨大成功。

I don't have any statistics regarding compression rates, but I'd been using the SharpZipLib library for years with much success.

终弃我 2024-09-07 13:49:52

好吧,我尝试像递归数据一样压缩,很有趣。检查我的示例:

private byte[] CompressWithLevels(byte[] data)
{
    using(MemoryStream ms = new MemoryStream())
    {
        using(GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
        {
            gz.Write(data, 0, data.Length);
            return ms.ToArray();
        }
    }
}

现在,我尝试压缩太大的文件,例如:

string path = @"c:\test.bin";
byte[] buffer = File.ReadAllBytes(path);
byte[] level1 = CompressWithLevels(buffer);
byte[] level2 = CompressWithLevels(level1);

检查缓冲区、level1 和 level2 的大小。
缓冲区大小为 77683,level1 = 57354,level2 = 8202...

缓冲区为 100%,则:
57354 是 73,83%
8202 是 10.55%
太有趣了。

Well, I try to compress like recursive data, is funny. Check my example:

private byte[] CompressWithLevels(byte[] data)
{
    using(MemoryStream ms = new MemoryStream())
    {
        using(GZipStream gz = new GZipStream(ms, CompressionMode.Compress))
        {
            gz.Write(data, 0, data.Length);
            return ms.ToArray();
        }
    }
}

Now, I try to Compress a file too big, for example:

string path = @"c:\test.bin";
byte[] buffer = File.ReadAllBytes(path);
byte[] level1 = CompressWithLevels(buffer);
byte[] level2 = CompressWithLevels(level1);

Check the size of buffer, level1 and level2.
buffer size is 77683, level1 = 57354 and level2 = 8202...

buffer is 100%, then:
57354 is 73,83%
8202 is 10,55%
so funny.

王权女流氓 2024-09-07 13:49:52

您还可以将开源 ZLib (http://www.zlib.net/) 与 PInvoke 结合使用,或使用它的包装器(我使用过 zlib.net - http://www.componentace .com/zlib_.NET.htm - 但我相信它有一些错误)。
它不如托管库方便,但比 DeflateStream/GZipStream 更高效(除了 GZipStream 中额外的 CRC 之外,它们是相同的)。

you can also use the open source ZLib (http://www.zlib.net/) with PInvoke, or use a wrapper for it (I've used zlib.net - http://www.componentace.com/zlib_.NET.htm - but I believe it had some bugs).
it's less convenient than managed libraries, but more efficient than DeflateStream/GZipStream (which are the same except for an extra CRC in GZipStream).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文