473,804 Members | 3,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

KJ
I am using the System.Compress ion.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

May 30 '06 #1
1 3308


--
William Stacey [MVP]

"KJ" <n_**********@m ail.com> wrote in message
news:11******** **************@ r44g2000cwb.goo glegroups.com.. .
|I am using the System.Compress ion.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.
--
wjs
May 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2197
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 compressed folder app. using DeflateStream resulted in the same error. am i missing something simple? thanks, Craig Buchanan
1
3095
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 item. A hack here http://www.geekpedia.com/tutorial191_Unzipping-compressed-files-using-GZipStream.html shows that you can get the last 4 bytes of the stream and convert it into an integer "size". But this doesn't seem right to me. I could also...
1
2154
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 as follows: Dim sourcefile As FileStream = File.OpenRead(inFileName) Dim destFile As FileStream = File.Open(outFilename, FileMode.Create, FileAccess.Write)
1
3639
by: hakan.thornqvist | last post by:
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();
1
10209
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 note that they'll create different-sized compressed files depending on the procedure you use to take in the source file's data. With one, almost every file I feed them for compression ends up significantly bigger. That code is below, almost verbatim...
4
3460
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.
2
2950
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 loading the gzip data! Im using the default buffer of the stream that i open on the 20GB gzipped file and pass it into the GZipStream ctor. then System.IO.Compression.GZipStream takes an hour! when just loading 50GB file of data takes a few minutes!
5
2950
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 loading the gzip data! Im using the default buffer of the stream that i open on the 20GB gzipped file and pass it into the GZipStream ctor. then System.IO.Compression.GZipStream takes an hour! when just loading 50GB file of data takes a few minutes!
11
7593
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 stream.Write(buffer, offset, count);
0
9708
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10589
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.