#!/usr/bin/perl
# base64_to.pl -- Echo binary files in base64
# ascii@ush.it

use strict;
require "base64.pl";

if ($#ARGV != 0) {
 print "usage: $0 filename\n";
 exit;
}

my ($file_name, $buf, $data, $data_size, $file_size);

print STDERR "$0 -- Echo binary files in base64 -- ascii\@ush.it\n";

$file_name = $ARGV[0];

open FILE, $file_name or die $!; 
binmode FILE;

print STDERR "Reading [ ";
while (($data_size = read FILE, $data, 1024) != 0) { 
 print STDERR ".";
 $file_size += $data_size;
 $buf .= $data; 
} 
close(FILE);
print STDERR " ] Done!\n";

print &base64'b64encode($buf);
print STDERR "Read saw $file_size bytes.\n";
