[erlang-questions] zlib compress and uncompress on bit string << 255, 3:2 >>.

rgowka1 rgowka1@REDACTED
Thu Oct 28 03:15:00 CEST 2010


Intuitively, when one uses a loss-less compression algorithm the input
should match the decompressed compressed input. In this case I was
naively thinking that zlib:uncompress( zlib:compress ( << 255, 3:2 >>
)) would give me back << 255, 3:2 >>. I agree with you about the
expected input and output being binary and that makes sense. But
somehow I still feel that the basic tenet of loss-less compression is
not true here. Again all of this is based on my very limited knowledge
of Erlang and the theory of compression..

Anyway, are there any functions to compress and uncompress bitstrings?

On Wed, Oct 27, 2010 at 8:54 PM, Kostis Sagonas <kostis@REDACTED> wrote:
> rgowka1 wrote:
>>
>> Hi -
>>
>> I am using zlib:compress and uncompress on bitstring.
>>
>> The expression zlib:uncompress( zlib:compress ( << 255, 3:2 >>  )) =:=
>> << 255, 3:2 >> is evaluating to false.
>>
>> zlib:uncompress( zlib:compress ( << 255, 3:2 >>  )).
>> <<"ÿ">>
>>
>> << << X >> || << X:1 >>  <= <<"ÿ">>  >>.
>> <<1,1,0,0,0,0,1,1,1,0,1,1,1,1,1,1>>
>>
>>  << << X >> || << X:1 >>  <= << 255, 3:2 >>  >>.
>> <<1,1,1,1,1,1,1,1,1,1>>
>>
>> Is this a bug with the zlib library or am I missing something basic here?
>
> What exactly makes you consider it a bug?
>
> The manual clearly mentions that zlib:uncompress/1 returns a binary().
> Why do you expect that equality of this term with a bitstring() which is not
> a binary() should succeed?
>
> Kostis
>


More information about the erlang-questions mailing list