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.

1

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.