strange zlib behavoiur

Gaspar Chilingarov nm@REDACTED
Tue May 9 01:57:50 CEST 2006


Hello all!

While trying to use zlib, I've got some strange results.
Please see following example


23> Z = zlib:open().		% openning zlib port
#Port<0.98>
% default does not work too.
24> zlib:deflateInit(Z, best_compression).
ok
% just putting several Kb of data
25> zlib:deflate(Z,list_to_binary( [ random:uniform(255) || X <-
lists:seq(1,5000) ])).
[]
26> zlib:deflate(Z,list_to_binary( [ random:uniform(255) || X <-
lists:seq(1,5000) ])).
[]
27> zlib:deflate(Z,list_to_binary( [ random:uniform(255) || X <-
lists:seq(1,5000) ])).
[]

% no output yet from zlib library -- calling it with sync flag to get
% some data - please note, that it should be called several times
% to output all data
28> zlib:deflate(Z, <<>>, sync).
[<<120,..............,144,...>>]
29> zlib:deflate(Z, <<>>, sync).
[<<8,...>>]
30> zlib:deflate(Z, <<>>, sync).
[<<146,1...>>]
31> zlib:deflate(Z, <<>>, sync).
[<<149,...>>]
32> zlib:deflate(Z, <<>>, sync).

% it have no more data to output - so zlib crashes.
% just same behavoiur with full flush mode

=ERROR REPORT==== 9-May-2006::04:38:41 ===
Error in process <0.57.0> with exit value:
{buf_error,[{zlib,call,3},{zlib,deflate,3},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}


In other hand in documentation of zlib module noted -

deflate/3 compresses as much data as possible, and stops when the input
buffer becomes empty. It may introduce some output latency (reading
input without producing any output) except when forced to flush.

*that's ok*

If the parameter Flush is set to sync, all pending output is flushed to
the output buffer and the output is aligned on a byte boundary, so that
the decompressor can get *all input data available so far*. Flushing may
degrade compression for some compression algorithms and so it should be
used only when necessary.


*should* I understand this as deflate should output *all* compressed
data it have at this moment - so calling deflate(Z, <<>>, finish) will
not procude any more data?

If not -- this is quite unclear from documentation -- I got such
suspects only writing this e-mail.


WIth best regards, Gaspar

-- 
Gaspar Chilingarov

System Administrator,
Network security consulting

t +37491 419763 (mob)
i 63174784
e nm@REDACTED



More information about the erlang-questions mailing list