G'day, monks. I've been playing with SQLite alot lately, and I'm trying to find a way to add binary attachments to the database. The SQLite docs recommend Base64 encoding, so I thought I'd experiment with that a bit.

Here's my program to encode files in Base64:

#! /usr/bin/perl use strict; use MIME::Base64 qw( encode_base64 ); use IO::All; encode_base64( io( $ARGV[0] )->slurp ) > io( $ARGV[1] ); __END__

And the matching decode program:

#! /usr/bin/perl use strict; use MIME::Base64 qw( decode_base64 ); use IO::All; decode_base64( io( $ARGV[0] )->slurp ) > io( $ARGV[1] ); __END__

Here's what I tried to test it:

Z:\>perl encode_base64.pl yearsinservice.pdf yis.b64 Z:\>perl decode_base64.pl yis.b64 yis.pdf

When I try to open yis.pdf with Acrobat Reader, it says there's an error in the file. The original PDF works fine. Any suggestions?

UPDATE: I moved these PDFs to my Linux box and used hexdump -C to look at them - it looks like an endline issue (yis.pdf has Windows-style endlines). I tried adding local $/ = "\n"; to each file, but that didn't seem to help.


_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

In reply to Problem Encoding/Decoding PDF with MIME::Base64 by DamnDirtyApe

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.