File zipped but not compressed

Jul 26, 2011 at 3:52 PM
I have the function below that I assume will compress and zip my file. But the streamed derived from the zipped file is the same as the uncompressed file. I know that zipping is not the same as compressing. I dont understand why the file is only zipped and it not compressed.
public System.IO.MemoryStream Compress(string filePath)
            System.IO.MemoryStream stream = new MemoryStream();

            using (ZipFile zip = new ZipFile())
                zip.UseZip64WhenSaving = Zip64Option.AsNecessary;  //for large file                 

                zip.AddFile(filePath, "");
                return stream;
Jul 26, 2011 at 10:59 PM

I don;'t know what you mean by "the stream derived from the zipped file is the same as the uncompressed file".  The same?  How? 

You'll have to be a little more precise.

The Zip format uses DEFLATE or some other compression format to squish the file data.  But this won't work very well for a previously-compressed file, like MP3, JPG, .mkv, or (lots of other formats).  So it is possible to zip a file, which then reduces its size maybe 3% ??  and the resulting zip file is approximately the same as the so-called "uncompressed" file.

What kind of file are you trying to zip?  Is it possible that the file is in a format that is already compressed ? 


Jul 27, 2011 at 12:38 AM

Sorry for the lack of clarity. What I meant was that when I zipped the file and saved it to a memory stream. I am currently away from development computer but I am pretty certain that the files that I am trying to zip are either JPEG, PNG or GIF files. So, that might be the issue. :(

I was using this library because we had some files (mainly images) to send over a network. I felt that file compression would have improved the time for the files to be transferred. I guess I am back to 1^2.

Jul 27, 2011 at 1:43 AM

Yah, zipping won't squish a JPG, GIF or PNG.  They all use compression internally.  when dealing with such images, the only benefit a zip would potentially give you is, packaging a set of images together into a single file.

Jul 27, 2011 at 3:30 AM

Thanks for the info.