Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#, Decompress a stream using zlib

I am trying to decompress a byte array.

byte[] bloc = { 120, 156, 211, 97, 144, 76, 247, 142, 98, 228, 98, 0, 2, 70, 101, 6, 166, 8, 16, 131, 133, 131, 145, 129, 209, 134, 129, 133, 1, 44, 12, 4, 202, 118, 12, 0, 70, 22, 2, 148 };

As you can see the header is 120 165 (78 9c in hex) witch is the zlib default Compression algorithme. I used the ComponentAce.Compression.ZipForge from the zlib site. I couldn't find samples on how to unzip streams(not files).

like image 479
user3468143 Avatar asked Nov 27 '25 21:11

user3468143


1 Answers

Use SharpZipLib. It includes a full interface to zlib, and will decompress zlib streams as well as other compressed data formats such as gzip, zip, bzip2, and raw deflate.

You should avoid the .NET components provided by Microsoft as they are buggy (in particular in not properly detecting invalid input) and Microsoft has stated that they will not fix it.

like image 143
Mark Adler Avatar answered Nov 30 '25 10:11

Mark Adler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!