gpt4 book ai didi

c# - 为什么我在不同的机器上使用 DeflateStream 有不同的压缩字节数组大小

转载 作者:行者123 更新时间:2023-11-30 22:13:26 24 4
gpt4 key购买 nike

我正在使用 DeflateStream 在我的机器上压缩短字符串

public byte[] Compress(byte[] oryginalBytes)
{
using (var msi = new MemoryStream(oryginalBytes))
using (var mso = new MemoryStream())
{
using (var gs = new DeflateStream(mso, CompressionMode.Compress))
{
msi.CopyTo(gs);
}

return mso.ToArray();
}
}

然后运行这段代码:

Compress(Encoding.Unicode.GetBytes("[TEST]"));

在我的机器上(windows 7 64 位)我得到了 12 个元素的字节数组:

139 102 8 97 112 101 8 6 146 177 12 0

然后在我的构建服务器(Windows 2008 64 位)上运行它,我有 120 个元素的字节数组。

236 189 7 96 28 73 150 37 38 47 109 202 123 127 74 245 74 215 224 116 161 8 128 96 19 36 216 144 64 16 236 193 136 205 230 146 236 29 105 71 35 41 171 42 129 202 101 86 101 93 102 22 64 204 237 157 188 247 222 123 239 189 247 222 123 239 189 247 186 59 157 78 39 247 223 255 63 92 102 100 1 108 246 206 74 218 201 158 33 128 170 200 31 63 126 124 31 63 34 190 247 107 188 249 53 78 127 141 215 244 239 247 127 141 255 39 0 0 255 255

有人知道为什么这个行为如此奇怪吗?

最佳答案

DeflateStream manual

This class represents the Deflate algorithm, which is an industry-standard algorithm for lossless file compression and decompression. Starting with the .NET Framework 4.5, the DeflateStream class uses the zlib library. 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.

关于c# - 为什么我在不同的机器上使用 DeflateStream 有不同的压缩字节数组大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19162712/

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