tags:

views:

60

answers:

2

I have a Java program that opens a socket connection to a server that streams Zip compressed data. I read(bytebuffer) from the stream, setInput(bytebuffer) on the zip object, and inflate(outputbuffer) to get my uncompressed data.

What would be the equivalent in python?

Here is the java code:

byte[] compressedBytes = new byte[1024];
int bytesRead = inputStream.read(compressedBytes);
zip.setInput(compressedBytes, 0, bytesRead);
zip.inflate(uncompressedBytes, 0, 1024);

Or, to summarize, I need a streaming inflate (not file based) zip option for python.

+1  A: 

Have a look at zlib.decompressobj(). I think that should give you what you want. See http://docs.python.org/library/zlib.html

Duncan
+1  A: 

You're looking for the zlib module. java.util.zip is actually an implementation using zlib, not Zip(aka PKZIP).

d.w.
Thanks! This has got me almost all the way there. Now, I'm having an issue with calling decompress in a loop.
abendigo