[erlang-questions] zlib design flaw?

Loïc Hoguin essen@REDACTED
Wed Sep 24 12:07:28 CEST 2014


On 09/24/2014 11:09 AM, Richard A. O'Keefe wrote:
> I'm a little bit puzzled here.
> According to zlib.h, the underlying C code works with
> input and output buffers.  Decompression is done in
> chunks, and one reason for a chunk stopping is that the
> output buffer has filled up.  I would expect a zlib
> interface to say "give me the decompressed information
> in chunks no bigger than this, as and when I ask for them".

I believe it does. From http://www.zlib.net/manual.html#Usage

 > The application must update next_in and avail_in when avail_in has 
dropped to zero. It must update next_out and avail_out when avail_out 
has dropped to zero.

So it should be possible to check if we are above a certain size when 
avail_out drops to 0, and return the data decompressed so far.

Looking at implementations I can see that PHP is doing just that. On the 
other hand Python has no max length parameter and instead relies on 
process-wide limits.

-- 
Loïc Hoguin
http://ninenines.eu



More information about the erlang-questions mailing list