deflatestream compression

T

Tony Johansson

Hello!

This program compress the string test.
The variable document is 8 bytes long after having done this statement
byte[] document = new UnicodeEncoding().GetBytes("test");
If I look at the variable result it is 111 bytes long.

So my question is if I have missed something here or is the overhead so
great when compressing very small amout of data ?

static void Main(string[] args)
{
byte[] document = new UnicodeEncoding().GetBytes("test");
MemoryStream strm = new MemoryStream();
DeflateStream deflate = new DeflateStream(strm,
CompressionMode.Compress);
deflate.Write(document, 0, document.Length);
deflate.Close();
byte[] result = strm.ToArray();
}

//Tony
 
J

James A. Fortune

So my question is if I have missed something here or is the overhead so
great when compressing very small amout of data ?

An approximate upper bound for Flate compression, IIRC, is
(NumberOfBytes * 1.1) + 12, so obtaining anything over that makes me
suspicious. That upper bound represents the worst possible case (no
compression plus additional space for the compression info). I regret
that I didn't keep the reference I used to obtain that upper bound
expression. I also recall that Flate/Zip compression is related to or
uses the Lemple-Ziv-Welsh (LZW) compression algorithm so check out:

http://en.wikipedia.org/wiki/Lempel–Ziv–Welch

My comments don't give the answer to what you missed, but it might
point you in the right direction. Perhaps someone else can provide
more detailed information.

James A. Fortune
(e-mail address removed)
 

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