It's been said before and before again, but here is another example of why you should never let yourself get locked into a particular way of thinking about a problem.

I'm working on a pure-Perl OpenPGP implementation (will be on CPAN in the next couple of days, Crypt::OpenPGP; the link will work when it's up :). And so on this particular day today I am working on the compression code, using Compress::Zlib.

Decompression worked fine, but I had a problem with compression: every time I would compress a data packet, GnuPG and PGP5 would have strange and mysterious errors when decompressing it. The errors usually didn't prevent the programs from decompressing the data, but they would die ugly deaths soon afterwards.

It turns out that the reason I was having the problem is because I am very, very stupid.

For the compression code I am using the relatively low-level Compress::Zlib interface (deflateInit, etc.) and after deflating, I am calling flush. And I was giving flush the Z_PARTIAL_FLUSH parameter, and then I tried Z_SYNC_FLUSH, etc. etc. The reason I did this is because when I was writing the compression code for Net::SSH::Perl, it took me a while to realize that I needed to use Z_PARTIAL_FLUSH. So I figured, why not save myself some time and just start using the "correct" flush type in the beginning.

This is a problem when the "correct" flush type is not so correct.

So I spent hours debugging the code, printing out hex dumps of the compressed and decompressed data, etc.

All the time not realizing that *the default*, Z_FINISH (which you get if you don't supply any args at all--hence default), is what works for PGP.


In reply to My Stupid Head, or why you should never stop thinking by btrott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.