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#."
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.
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
There's
or
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#.
来源:https://stackoverflow.com/questions/6522778/java-util-zip-deflater-equivalent-in-c-sharp