GZipStream, compressed date differs in size

H

hakan.thornqvist

I am using GZipStream for compression, and the size and contents of
the compressed byte array differs from time to time, using the same
source.

byte[] uncompressed = Enc.GetBytes(xmlNode.OuterXml);
byte[] compressed = compress(uncompressed);

private byte[] compress(byte[] uncompressed)
{
MemoryStream ms = new MemoryStream();
GZipStream gzStream = new GZipStream(ms,
CompressionMode.Compress);
gzStream.Write(uncompressed, 0, uncompressed.Length);
gzStream.Close();
return ms.ToArray();
}

Length of uncompressed data is 89368.
Running this a couple of times results in comressed length of
20260-20263, with different contents.
Decompression of the resulting byte array works fine i all cases
though.

Is this expected behavior?

// Håkan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top