GZipStream - compressed files end up larger, sometimes...

K

KJ

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 compressing
already-compressed formats such as jpeg.

Another less-consistent example of this behavior is found in the case
of compressing TIFFs, wherein some files end up greatly compressed (the
larger ones up to 93% compression ratio) and others end up larger than
the originals.

I have 2 questions:

a) Is there some way to know whether a file will actually compress
*before* perfoming the compression routine (aside from using its file
extension)?

b) Is there a way to gzip a file without doing compression when I know
that performing the compression routine will end up in a larger file?
It seems WinZip is able to do this by adding files to archives without
compressing them.

Thanks in advance.
-KJ
 
W

William Stacey [MVP]

--
William Stacey [MVP]

|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 compressing
| already-compressed formats such as jpeg.
|
| Another less-consistent example of this behavior is found in the case
| of compressing TIFFs, wherein some files end up greatly compressed (the
| larger ones up to 93% compression ratio) and others end up larger than
| the originals.
|
| I have 2 questions:
|
| a) Is there some way to know whether a file will actually compress
| *before* perfoming the compression routine (aside from using its file
| extension)?

AFAIK, the algo can't know until the algo actually runs over the data.

| b) Is there a way to gzip a file without doing compression when I know
| that performing the compression routine will end up in a larger file?
| It seems WinZip is able to do this by adding files to archives without
| compressing them.

You could just check the file size, and if bigger, just send the file
instead of adding to a single gz. I don't think you can just do an add
without compression.
 

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