sh1tn has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

The problem is MIME::Base64 decode(?) results under activestate Perl. The file size after the decode is always different (bigger than the original file):
use MIME::Base64; open my $reader, "TEST.gif"; while (read($reader, $buffer, 10*57)) { $file_data .= decode_base64(encode_base64($buffer, '')) } open my $writer, ">TEST_base64.gif"; print $writer $file_data; __END__ `dir` output: 11/24/2005 03:13 AM 66,072 TEST.gif 04/16/2006 09:28 PM 66,437 TEST_base64.gif

This is `perl -v`:
This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 25 registered patches, see perl -V for more detail)


Replies are listed 'Best First'.
Re: ActivePerl MIME::Base64 bug?
by idsfa (Vicar) on Apr 16, 2006 at 18:51 UTC

    binmode has bitten you.


    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
      Yes, it is binmode problem. Thank you ++.


Re: ActivePerl MIME::Base64 bug?
by borisz (Canon) on Apr 16, 2006 at 18:52 UTC
    My guess is, that one of your filehandles is not in binmode. Try if this makes a difference:
    use MIME::Base64; use Fatal qw/open/; my ( $buffer, $file_data ); open my $reader, '<:bytes', "TEST.gif"; while ( read( $reader, $buffer, 10 * 57 ) ) { $file_data .= decode_base64( encode_base64( $buffer, '' ) ); } open my $writer, '>:bytes', "TEST_base64.gif"; print $writer $file_data;
    Boris
      :bytes has nothing to do with line endings, :raw does. See PerlIO.