Colm,<br><br>This works without crashing:<br>-module(zlib_deflate_problem).<br>-export([start/0, start/1]).<br><br>-define(DATA_SIZE, 4000).<br><br>start() -><br> start(?DATA_SIZE).<br><br>start(DataSize) -><br> Data = <<0:DataSize/unit:8>>,<br>
io:format("Raw data -> ~p~n", [size(Data)]),<br><br> Z = zlib:open(),<br> ok = zlib:deflateInit(Z),<br> Deflated = zlib:deflate(Z, Data, finish),<br> ok = zlib:deflateEnd(Z),<br><br> io:format("Deflated -> ~p~n", [Deflated]),<br>
<br> ok = zlib:inflateInit(Z),<br> io:format("Inflate buf size -> ~p~n", [zlib:getBufSize(Z)]),<br><br> Inflated = case catch zlib:inflate(Z, Deflated) of<br> {'EXIT', {'data_error', _Backtrace} } -><br>
io:format("zlib:inflate data_error~n"),<br> [];<br> {'EXIT', Reason} -><br> io:format("zlib:inflate error -> [~p]~n", [Reason]),<br> [];<br> [] -><br>
io:format("zlib:inflate empty response~n"), [];<br> Iolist -><br> Iolist<br> end,<br><br> ok = zlib:inflateEnd(Z),<br> ok = zlib:close(Z),<br><br> io:format("Inflated -> ~p~n", [iolist_size(Inflated)]).<br>
<br>Hope this helps.<br>Ed<br><br><div class="gmail_quote">On Mon, May 19, 2008 at 1:55 PM, Colm <<a href="mailto:colm.dougan@gmail.com" target="_blank">colm.dougan@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I'm having a problem with erlang's zlib/deflate. The problem is that<br>
if I try to deflate a piece of data that is a multiple of 4000 bytes<br>
(which also happens to be the zlib internal buffer size, I noticed)<br>
and then inflate it I get an inflate exception. Below is some sample<br>
code.<br>
<br>
I realize I can set different internal buffer size using<br>
zlib:setBufSize but that doesn't really help as I can't predict the<br>
size of data I will be deflating/inflating.<br>
<br>
Am I doing something dumb here or is this a bug in the erlang zlib<br>
interface? I strongly suspect it is the former.<br>
<br>
Thanks,<br>
Colm<br>
<br>
<br>
<br>
-module(zlib_deflate_problem).<br>
-export([start/0, start/1]).<br>
<br>
-define(DATA_SIZE, 4000).<br>
<br>
start() -><br>
start(?DATA_SIZE).<br>
<br>
start(DataSize) -><br>
% Generate a binary of size "0" x DATA_SIZE<br>
Data = list_to_binary(<br>
lists:map(fun(_) -> 0 end, lists:seq(1, DataSize))<br>
),</blockquote><div>fyi, this would be MUCH easier as<br>Data = <<0:?DATA_SIZE/unit:8>>.<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
io:format("Raw data -> ~p~n", [size(Data)]),<br>
<br>
ZInflate = zlib:open(),<br>
ok = zlib:inflateInit(ZInflate),<br>
<br>
ZDeflate = zlib:open(),<br>
ok = zlib:deflateInit(ZDeflate),<br>
<br>
Deflated = zlib:deflate(ZDeflate, Data, sync),<br>
io:format("Deflated -> ~p~n", [Deflated]),<br>
<br>
Inflated = case catch zlib:inflate(ZInflate, Deflated) of<br>
{'EXIT', {'data_error', _Backtrace} } -><br>
io:format("zlib:inflate data_error~n"),<br>
[];<br>
{'EXIT', Reason} -><br>
io:format("zlib:inflate error -> [~p]~n", [Reason]),<br>
[];<br>
[] -><br>
io:format("zlib:inflate empty response~n"), [];<br>
Iolist -><br>
Iolist<br>
end,<br>
<br>
io:format("Inflated -> ~p~n", [iolist_size(Inflated)]),<br>
<br>
ok.<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
</blockquote></div><br>