[ale] Base64 encoding in Perl

Fletch fletch at phydeaux.org
Mon Feb 14 12:09:04 EST 2005


>>>>> "Christopher" == Christopher Fowler <cfowler at outpostsentinel.com> writes:

    Christopher> I'm trying to use MIME::Base64::encode to encode a 9m
    Christopher> binary file into Base64.  I'm using sysopen and
    Christopher> sysread on the file but I'm not sure how to append
    Christopher> the result of the read into a data buffer.

If you check down in the "EXAMPLES" section of "perldoc MIME::Base64"
it says you should just read and encode using a multiple of 57 bytes
to completely fill up a single base64 line:

          use MIME::Base64 qw(encode_base64);

          open(FILE, "/var/log/wtmp") or die "$!";
          while (read(FILE, $buf, 60*57)) {
              print encode_base64($buf);
          }

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org|  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U



More information about the Ale mailing list