19

I have a program (written in C#) that reads/writes its data directly (direct file access without server) to firebird database files. For a better exchange I want to (un)compress them on import/export for a better exchange over the internet without the need of an external program to (un)compress them.

I know #ziplib which supports Zip, GZip, Tar and BZip2.

What else free compression libraries for C# do you know? Is there a .NET library which supports LZMA so i can read/write ".7z" files?

Nikolai Samteladze
  • 7,699
  • 6
  • 44
  • 70
Xn0vv3r
  • 17,766
  • 13
  • 58
  • 65

5 Answers5

25

7-zip has a free source code, public domain C# SDK for the LZMA algorithm:

http://www.7-zip.org/sdk.html

Sebastian Dietz
  • 5,587
  • 1
  • 31
  • 39
22

There is a good article written by Peter Bromberg:

7Zip (LZMA) In-Memory Compression with C#

Shows a simple C# SevenZip.Compression.Lzma.SevenZipHelper class to enable high-compression of in-memory objects with C#. Adds a new 7Zip format LZMA Cookie Compression class to the previously published CookieCompression utility.

Kissaki
  • 8,810
  • 5
  • 40
  • 42
splattne
  • 102,760
  • 52
  • 202
  • 249
  • @Kissaki external links are okay for certain situations; including: 1)The amount of relevant external material is huge, for example a specification. 2) Links which are supporting information only 3) material which can't be copy-pasted due to copyrights – ChatGPT Mar 23 '19 at 01:16
  • 2
    I'm not sure why that specific web.archive.org URL was used in this answer but the source URL is http://www.nullskull.com/a/768/7zip-lzma-inmemory-compression-with-c.aspx. Also, some helpful information with examples can be found at https://stackoverflow.com/a/8605828/1039753. – Arvo Bowen Feb 07 '20 at 16:48
  • 1
    Keep in mind, Peter Bromberg's SevenZipHelper default class is extremely slow with the default properties. 3600 (6c/12t) vs 144Mb sql file: `default settings: 135 sec! -> 7.9Mb` vs `without properties (//encoder.SetCoderProperties): 34 sec -> 8.2Mb` vs `using 7zr.exe: 9 sec!!! 8.2Mb` Imo the programatical settings are not using all threads, only two of them, vs 7zr.exe which used at least 6 threads. – S0und Jul 15 '22 at 09:20
8

You may try SevenZipSharp

markhor
  • 2,235
  • 21
  • 18
4

It seems to be quite a little known fact but .NET library includes packaging/compression API

aku
  • 122,288
  • 32
  • 173
  • 203
  • Here is an example using that API: http://www.syntaxwarriors.com/2012/zip-files-using-c-net-without-any-extra-libraries/ – JensB Sep 23 '12 at 17:00
  • Is this MS specific? Nowaways I would not like to use a MS-only solution anymore. I mean if I pack a file, I would expect it to be used on non-MS-machines as well. – tmighty Mar 13 '14 at 14:39
  • @JensB that link is now dead. – Arvo Bowen Feb 07 '20 at 13:41
  • @ArvoBowen Look here: https://stackoverflow.com/questions/940582/how-do-i-zip-a-file-in-c-using-no-3rd-party-apis – JensB Feb 07 '20 at 14:05
  • 1
    @JensB great question to look at but I don't think that has anything to do with `7zip` (and that's why I came to see this question. I ended up getting the 7zip SDK from https://www.7-zip.org/sdk.html and read up on the article found at http://www.nullskull.com/a/768/7zip-lzma-inmemory-compression-with-c.aspx. I was able to use that guys `SevenZipHelper.cs` file with the SDK from 7-zip.org and got it to work. – Arvo Bowen Feb 07 '20 at 14:50
  • It has to do with the suggested answer. How to do it natively in C#. With no libraries, which is exactly what the dead link showed once upon a time. – JensB Feb 07 '20 at 16:02
1

If you are writing individual files, then you could just treat it as a stream and use the inbuilt GZipStream / DeflateStream (although in some tests I did, #ZipLib out-performed the MS offering for both ratio and speed). Or there is inbuilt zip support somewhere in the framework. I don't know about LZMA, though.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900