I'm building an network application that needs to be able to switch from normal network traffic to a zlib compressed stream, mid stream. My thoughts on the matter involve boolean switch that when on will cause the network code to pass all the data through a class that I can feed IEnumerable<byte> into, and then pull out the decompressed stream, passing that on to the already existing protocol parsing code.
Things I've looked at:
ZLib.NET - It seems a little... Ecclectic, and not quite what I want. Would still make a decent start to build off though. (Jon Skeet's comments here hardly inspire me either.)
SharpZipLib - This doesn't seem to support zlib at all? Can anyone confirm or deny this?
I would very much prefer and all managed solution, but let's have at it... are there any other implementations of this library out there in .NET, that might be better suited to what I want to do, or should I take ZLib.NET and build off that as a start?
PS:
Jon's asked for more detail, so here it is.
I'm trying to implement MCCP 2. This involves a signal being sent in the network stream, and everything after this signal is a zlib compressed data stream. There's links to exactly what they mean by that in the above link. Anyway, to be clear, I'm on the recieving end of this (client, not server), and I have a bunch of data read out of the network stream already, and the toggle will be in the middle of this (in all likelyhood atleast), so any solution needs to be able to have some extra data fed into it, before it takes over the NetworkStream (or I manually feed in the rest of the data).
SharpZipLib does support ZLib. Look in the FAQ.
Additionally, have you checked whether the System.IO.Compression namespace supports what you need?
I wouldn't use an IEnumerable<byte> though - streams are designed to be chained together.
EDIT: Okay... it sounds like you need a stream which supports buffering, but with more control than BufferedStream provides. You'd need to "rewind" the stream if you saw the decompression toggle, and then create a GZipStream on top of it. Your buffer would need to be at least as big as your biggest call to Read() so that you could always have enough buffer to rewind.
Included in DotNetZip there is a ZlibStream, for compressing or decompressing zlib streams of data. You didn't ask, but there is also a GZipStream and a DeflateStream. As well as a ZlibCodec class, if that is your thing. (just inflates or deflates buffers, as opposed to streams).
DotNetZip is a fully-managed library with a liberal license. You don't need to use any of the .zip capability to get at the Zlib stuff. And the zlib stuff is packaged as a separate (smaller) DLL just for this purpose.
I can recommend you Gerry Shaw's zlib wrapper for .NET:
http://www.organicbit.com/zip/
As far as I know the ZLib (gzip) library doesn't support listing the files in the header. Assuming that matters to you, but it seems a big shortcoming. This was when I used the sharp zip library a while ago, so I'm willing to delete this :)
Old question, but System.IO.Compression.DeflateStream is actually the right answer if you need proper zlib support:
Starting with the .NET Framework 4.5, the DeflateStream class uses the
zlib library. As a result, it provides a better compression algorithm
and, in most cases, a smaller compressed file than it provides in
earlier versions of the .NET Framework.
Doesn't get better than that.
Related
I have a database with data packed with LZRW1 algorithm and I need to read this data in a C# application. Does anyone know if there is a ready implementation of the LZRW1 decompression for C#?
I had a good look, I can't find any in C# or Java. I suspect it's a generational issue - that specific algorithm has been surpassed by ZIP etc and there was little reason to write the code in newer languages.
Below are some implementations in C++ and Pascal:
http://www.ross.net/compression/lzrw1.html
http://www.programmersheaven.com/download/14494/download.aspx
I'm trying to extract a .tbz file using .net
Anyone have any suggestions?
The file will be very large (3GB) if this makes any difference.
First you'll need to know about, how to implement, or use a supporting library for BZIP2 decompression. Then you will need to do the same, in a different fashion, and de-archive the contents of the resulting TAR file.
You can use SharpZipLib:
http://www.icsharpcode.net/opensource/sharpziplib/
However, it is licensed under the GPL, with an exception that I'm not familiar with, so you'll have to read carefully to see if it suits your needs.
I have a WCF Service and I want to send a message with the least characters possible.
Are there any compression methods to do this?
I want to compress it in C# and decompress it using javascript.
MTOM.
Or you could implement a custom message encoder and decoder, where you pass the data through a (de)compression engine. This implies you have control over both ends (client and service).
Unfortunately I don't know the answer to your updated question. You'd have to find some libraries that implement the same compression algorithm in both C# and Javascript. I've never done anything like that so I wouldn't know which libraries to use. You could try to manually implement something like LZW or DEFLATE, but that'll be the hard way and error-prone.
For that, you might implement one of the compression techniques explained here.
does anyone know how can I achieve java's Deflater.deflate() functionality in .NET so it would be understandable for java's Infalter.inflate() method?
regards,
Rafal
I have used #zipLib. It is pretty straight forward.
Taken from their site:
#ziplib (SharpZipLib, formerly NZipLib) is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform. It is implemented as an assembly (installable in the GAC), and thus can easily be incorporated into other projects (in any .NET language). The creator of #ziplib put it this way: "I've ported the zip library over to C# because I needed gzip/zip compression and I didn't want to use libzip.dll or something like this. I want all in pure C#."
ZlibStream class inside DotNetZip package (https://dotnetzip.codeplex.com/) is equivalent to java.util.zip.deflater.
Nuget: Install-Package DotNetZip
usage for byte array:
ZlibStream.CompressBuffer(dataBytesArray);
ZlibStream.UncompressBuffer(dataBytesArray);
it also has String compression and decompression, and the class can be used with streams exactly the same way as .NET DefalteStream. Please note that DeflateStream of DotNetZip is not the same as its Java, ZlibStream is.
Additional Info:
DeflateStream of .NET is not compatible with Deflate in Java. In fact, Java uses Zlib and adds 2-6 bytes header and 4 bytes checksum by default. Cutting off the bytes (suggested by some articles like http://blogs.msdn.com/b/bclteam/archive/2007/05/16/system-io-compression-capabilities-kim-hamilton.aspx) will work, but I don't suggest it as parsing header length may cause bugs.
I don't suggest SharpZipLib as it is pure C# and usually performance is important working with compression and decompression data. Look at http://www.codeproject.com/Articles/434583/SharpZipLib-or-DotNetZip-Which-should-you-use
Check System.IO.Compression namespace. It has DeflateStream. DeflateStream uses Deflate algorithm for compression, and so does java.util.zip.deflater. So you can compress with .NET and decompress with Java implementation and vice versa.
There's
ZipPackage Class
or
GZipStream Class
which might help, but I don't know how easy they are to use or if compatible with java (sorry not a great answer).
There's a nice blog post about zip stuff in: http://blogs.msdn.com/b/bclteam/archive/2010/06/28/working-with-zip-files-in-net.aspx
Or a few open source zip utilities around for c#.
Does anyone know of an open source H.264 encoder in C# (or any other managed language)? I might be able to make do with a python implementation as well.
The libraries that I’ve found (e.g. x264) are written in pretty low level c (procedural with lots of macros) and assembly. Tweaking them is turning out to be far more complex than I'd thought. My project has no concern for performance or compatibility. We just want to test how some ideas will impact the perception of the outputted video.
We’d be willing to pay for or license the code if need be.
Thanks in advance!
Edit - Some important points:
I don't care about performance (e.g. real time encoding) at all. It could take 10 days to encode for all I care.
A wrapper isn't helpful since I want to actually modify the encoder itself.
No one would likely spend the time to develop the codec in those languages because they would be hopelessly slow for actual encoding. However, the reference implementation should be less optimized and more useful to you. It is still in C.
http://iphome.hhi.de/suehring/tml/download/
I don't think there is already such a port you need - you'll find wrappers for any langugae but a pure implementation does not have the critical mass. I'd recommend to port it yourself, document your port well and then start tweakening it.
If you'd want to port some encoder to C#, this should be easier to start with - about 8k LOC: http://sourceforge.net/projects/fevh264/
How about http://www.ffmpeg-csharp.com/?