Why I have different compression byte array sizes using DeflateStream on different machines

StackOverflow https://stackoverflow.com/questions/19162712

  •  30-06-2022
  •  | 
  •  

Pergunta

I'm compressing short string on my machine using 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();
    }
}

And run this code:

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

On my machine (windows 7 64 bit) I get 12 elements byte array:

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

And running this on my build server (Windows 2008 64bit) I have 120 elements byte array.

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

Anybody has an idea why this behave so strange?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top