4

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.

abendigo
  • 954
  • 1
  • 8
  • 31

2 Answers2

1

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

Duncan
  • 92,073
  • 11
  • 122
  • 156
1

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

David Harks
  • 730
  • 4
  • 5
  • Thanks! This has got me almost all the way there. Now, I'm having an issue with calling decompress in a loop. – abendigo Jun 23 '10 at 18:14