gpt4 book ai didi

c# - GZipStream 机器依赖

转载 作者:可可西里 更新时间:2023-11-01 07:43:53 26 4
gpt4 key购买 nike

我在 .NET 4.0 中遇到了一些奇怪的依赖于机器/操作系统的 GZipStream 行为。这是相关代码:

public static string Compress(string input) {
using(var ms = new MemoryStream(Encoding.UTF8.GetBytes(input)))
using(var os = new MemoryStream()) {
using(var gz = new GZipStream(os,CompressionMode.Compress,true)) {
ms.CopyTo(gz);
}
return string.Join("",os.ToArray().Select(b=>b.ToString("X2")));
}
}

运行 Compress("freek") 给我

1F8B08000000000004004B2B4A4DCD06001E33909D05000000

在 Windows 7 上

1F8B0800000000000400ECBD07601C499625262F6DCA7B7F4AF54AD7E074A10880601324D8904010ECC188CDE692EC1D69472329AB2A81CA6556655D661640CCED9DBCF7DE7BEFBDF7DE7BEFBDF7BA3B9D4E27F7DFFF3F5C6664016CF6CE4ADAC99E2180AAC81F3F7E7C1F3F22CEEB3C7FFBFF040000FFFF1E33909D05000000

在 Windows Server 2008R2 上。两者都是 64 位的。我希望结果是一样的。

当我解压缩任一结果时,两台机器都给出了正确的结果。我已经发现在 W7 上 ms.Length == 25 而在 W2K8R2 上 ms.Length==128,但不知道为什么。

这是怎么回事?

最佳答案

It was announced that .NET 4.5 Beta includes zip compression improvements to reduce the size :

Starting with the .NET Framework 4.5 RC, the DeflateStream class uses the zlib library for compression. As a result, it provides a better compression algorithm and, in most cases, a smaller compressed file than it provides in earlier versions of the .NET Framework.

您是否在 Win7 计算机上安装了 .Net 4.5+?

关于c# - GZipStream 机器依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9806381/

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