ZLIB and .NET

Steve Gilham has been involved in some odd experiments with a codebase involving IronPython, Jython and Scala (with Erlang occasionally in the mix as well).

His latest post shows the IronPython code needed for ZLIB compression on .NET, even though it isn't provided directly by the framework:
A recurring problem in several of the projects I have in the pipeline is the matter of handling ZLIB. Java, though java.util.zip offers ZLIB compression with a 32k byte window (but no means of tuning the window) through the DeflaterOutputStream. The .Net framework doesn't offer direct ZLIB at all, but provides naked Deflate via System.IO.Compression.DeflateStream.

That gives us enough to be able to reflate the output of a ZLIB deflation, since a ZLIB is a 2 byte header, a deflate section and finally a 4 byte checksum.

That works fine; but the converse, taking a .Net deflate and adding the appropriate top and tail took a bit of getting to work.

First pitfall -- the InflaterInputStream has to be read in chunks as large as feasible, rather than byte at a time, so as not to throw a premature EOFException. That overcome, I got a result of the right length, but differing in the final few characters for the file under test, which I resolved by doing a belt-and-braces closing of the deflate operation. The un-refactored code I currently have continues from the above as...
This should allow me to simplify the baggage accumulated for the C#/Erlang bridge, which currently uses a second-generation port of the original 'C' ZLIB for this sort of interoperation.

Comments

Popular posts from this blog

Extending Abobe Flash Player and AIR with Python and Ruby

Should Python Projects Support IronPython and Jython?

Further Adventures of the Debugger