By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,570 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,570 IT Pros & Developers. It's quick & easy.

GZipStream, compressed date differs in size

P: n/a
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

Jun 29 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Yes, compression rates vary depending on source data.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"ha**************@gmail.com" wrote:
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

Jun 29 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.