Click here to Skip to main content
11,921,354 members (69,317 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
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 6: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 Smile | :)

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
0 OriginalGriff 493
1 Dave Kreskowiak 220
2 phil.o 170
3 Sergey Alexandrovich Kryukov 157
4 KrunalRohit 134
0 OriginalGriff 7,036
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,286
3 George Jonsson 2,840
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 4 Nov 2012
Copyright © CodeProject, 1999-2015
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