CompressionLevel does not change

Nov 8, 2009 at 3:29 PM

Hi all,

Im trying to zip a directory into a zip file.

The output zip file's size doesn't change, although Im

changing the CompressionLevel from 0 to 9.

Here is the relevant code:(VB.Net 2005)

----------------------------------------------------------------------------

Using zip As New ZipFile()
            zip.StatusMessageTextWriter = System.Console.Out
            zip.AddDirectory("C:\Temp\")
            zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level1
            zip.UseZip64WhenSaving = Ionic.Zip.Zip64Option.Never
            zip.Save("C:\1.zip")

End Using

----------------------------------------------------------------------------

Does anyone know what am I missing here?

Thanks anayway.

Ofer

 

 

Coordinator
Nov 8, 2009 at 3:59 PM

yes.

from the doc:

As with some other properties on the ZipFile class, like Password, Encryption, and ZipErrorAction, setting this property on a ZipFile instance will cause the specified CompressionLevel to be used on all ZipEntry items that are subsequently added to the ZipFile instance. If you set this property after you have added items to the ZipFile, but before you have called Save(), those items will not use the specified compression level.

Try this:

Using zip As New ZipFile()
            zip.StatusMessageTextWriter = System.Console.Out
            zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level1
            zip.UseZip64WhenSaving = Ionic.Zip.Zip64Option.Never
            zip.AddDirectory("C:\Temp\")
            zip.Save("C:\1.zip")
End Using

Nov 9, 2009 at 6:03 AM

Hi Cheeso,

I'd tryed it, but it doesn't change the compression or file size.

My problem remains the same.

Thanks

 

Coordinator
Nov 9, 2009 at 6:05 AM

What are you compressing, exactly?  If it's previously compressed, it won't compress any further.

Nov 9, 2009 at 6:36 AM

Today we are using WinZip for each directory

we want to zip inorder to send it to our customers.

We wanted to develop a .net app so we wont have to

zip it with WinZip for each customer.

The dir contains a few jpg's & Tifs.

The customer has an old program that uses cmd to unzip the file:

UNZIP -s -o NewZipFile.Zip -d C:\Temp

We see different sizes between the old winZip file and the new zip file.

Also we see different outputs when the customer runs the commandline:

The old file (using WinZip) - the output writes: Inflating......

The new file (using Ionic) - the output writes: Extracting.......

I read that the difference is because the new file is not compressed,

so thats why I want to know how to make the compressionlevel to work.

Hope I'm more clear now,

Ofer

 

Coordinator
Nov 9, 2009 at 8:07 AM

Yes, more clear, thanks.

Here's an idea: In the older version of the library, there was a heuristic that always applied a CompressionLevel.None for some document types.  I think that included .jpg files.

What version of the library are you using?  Have you tried v1.9? 

 

 

Nov 9, 2009 at 8:50 AM

It wokrs!!!!

Thank you very much Cheeso.

I was using v 1.8. The problem was solved after updrading to v1.9.

You were right about changing the compression level before

adding the the directory. I tryed to change the order and it doesn't work.

The following code Works great:

zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level1
zip.UseZip64WhenSaving = Ionic.Zip.Zip64Option.Never
zip.AddDirectory("C:\Temp\")
zip.Save("C:\1.zip")

Thank again!!!!!

(-',

 

Coordinator
Nov 9, 2009 at 10:12 AM
Edited Nov 9, 2009 at 10:15 AM

Great!  Glad it works for you.

Good luck to you.

ps: do me a favor, if you can.  Rate the release at this link:

http://dotnetzip.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27890

(Scroll down to the bottom of the page to see the ratings button)