Click here to Skip to main content
13,556,206 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi everyone, im trying to develop a program using c# to compress files, but im with doubts:

1st - should i try to use one algorithm to compress all kind of files? any sugestion of algorithm?

2nd - divide the files in category's like


And use diferent algoritms? any sugestion of what should i use for each one of them?

Thanks in advance
Hug [[]]
Posted 4-Nov-12 5:33am
pasztorpisti 4-Nov-12 15:42pm
Its also important to note in case of compression algorithms that all of them have a specific tradeoff between good compression ratio and speed. For example in case of the general purpose 7zip: it has probably one of the best compression ratios however its lzma is quite computation intensive and this might be a downside when you are searching for something to use on a mobile device. Sometimes the extra compression ratio might not be a good enough reason to use a compressor instead of another that has worse compression ratio for much less computation power. We recently dropped lzma from a mobile project because the load times were not satisfying (with lzma: 20 secs, without: 5 secs) on android/arm platform (despite the fact that on the dev platform - win32 - it wasn't noticable). You should try several solutions before choosing one that is suitable for your needs. Also note that sometimes the time needed for compression isn't important because sometimes the final product contains only the decompressor to load its data and that can be an important factor! In this case a library that comes with fast general-purpose compression method and one slow ultra-compression feature to use before software release can be awesome!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Have a look at #ziplib[^]

It's fairly easy to use, so you can try out the various algorithms on the files you want to compress.

Best regards
Espen Harlinn
Sure, my 5. I also recommend 7zip for .NET. However, OP probably needs some explanation. Please see my answer.
Espen Harlinn 4-Nov-12 11:51am
I did :-D
Thank you. :-)
Maciej Los 4-Nov-12 13:03pm
Short and to the point, my 5!
Espen Harlinn 4-Nov-12 14:59pm
Thank you, Maciej :-D
pasztorpisti 4-Nov-12 15:45pm
5ed, zip is good start (and can be a good finish too).
Espen Harlinn 4-Nov-12 15:51pm
Thank you, #ziplib supports bzip2 too, and it's surprisingly fast for a piece of managed code
pasztorpisti 4-Nov-12 15:58pm
Managed code is interesting because with a good jit it can achieve good performance on many platforms.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Having compression lossless makes a great difference compared with different lossy algorithms. While lossy algorithms differ dramatically depending on the nature of the data, with lossless algorithms, it's not so much so. It all depends on how much do you want to optimize your algorithm to the specific nature of data. Even with lossless compression, taking into account the nature of data it could be very useful for compression ratio, doing it is much more difficult. At the same time, general-purpose lossless algorithms are well-known, open source implementations are available, so I'm not sure if you even need to develop anything. (Can you find such implementation by yourself, or you might need some help?)

Please see:[^].[^].

Good luck,
Espen Harlinn 4-Nov-12 11:50am
Sure enough, a 5 :-D
Thank you, Espen.
Maciej Los 4-Nov-12 13:04pm
Agree, +5!
Thank you, Maciej.
pasztorpisti 4-Nov-12 15:49pm
+5, Mentioning lossy is very important in case of video and audio!
Thank you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

I agree with you guys :)

But, Espen Harlinn can i choose the algoritm that will be used to compress a file using that library ?

The kind of compression that i want to apply is only lossless...

Any sugestion for the best algoritm to use?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180515.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100