473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

Jun 29 '07 #1
1 3593
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Craig Buchanan | last post by:
when i try to open a file that has been compressed with GZipStream (source from microsoft's 101 Samples for Visual Studio 2005), i get an "invalid archive" message from winzip, zipgenius and xp's...
1
by: KJ | last post by:
I am using the System.Compression.GZipStream class, and I noticed that in certain cases, the resultant compressed file is actually larger than the original. This is almost a constant when...
1
by: Robinson | last post by:
I'm trying to work out how to decompress a GZipStream. I'm not sure how to allocate the destination buffer, given that I cannot query the stream to find out the total decompressed size of the...
1
by: prince.matt | last post by:
Hi, I am using GZipStream to compress a simple text file approx 24MB in size. I am finding that the destination "compressed" file is several MB larger than the source file (31MB). The code is...
1
by: sedwick | last post by:
I'm using .NET 2.0.50727 in VS 2005 Pro, ENU Service Pack 1 (KB926601). I've been experimenting with the System.IO.Compression classes GZipStream and DeflateStream, and I found it interesting to...
6
by: =?Utf-8?B?QkRSaWNoYXJkc29u?= | last post by:
Hi, I have been using the new GZipStream classes, and have been experiencing problems when attemping to decompress files, which from experience, seem to be failing when the original file size...
4
by: Arnie | last post by:
Folks, The GZipStream class in .NET is throwing an exception during an OS unseal/power up (first boot experience). The .NET system is fully up as other apps seem to run fine.
5
by: DR | last post by:
Why is its substantialy slower to load 50GB of gzipped file (20GB gzipped file) then loading 50GB unzipped data? im using System.IO.Compression.GZipStream and its not maxing out the cpu while...
11
by: mach77 | last post by:
When using a GZipStream, is there any way to know how many compressed bytes were written? For example: // "buffer" is data from a text file // "offset" is 0 // "count" is 100 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.