Connecting Tech Pros Worldwide Help | Site Map

GZipStream, compressed date differs in size

 
LinkBack Thread Tools Search this Thread
  #1  
Old June 29th, 2007, 09:25 AM
hakan.thornqvist@gmail.com
Guest
 
Posts: n/a
Default GZipStream, compressed date differs in size

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


  #2  
Old June 29th, 2007, 05:45 PM
=?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=
Guest
 
Posts: n/a
Default RE: GZipStream, compressed date differs in size

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#


"hakan.thornqvist@gmail.com" wrote:
Quote:
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
>
>
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.