[ic] Base64 - UserTag
Lars Tode
lars.tode at bpanet.de
Fri Oct 14 02:36:33 EDT 2005
Hi list and developers,
Fews days ago, I created this base64 - UserTag.
This Tag can encode data in base64 and decode it from base64.
I've not testet the file functions, but tue cgi_in works fine :)
May be it's something for the CoreTags, or standard Interchange.
Feel free to use ^^
--snip--
UserTag base64 Order file_in file_out cgi_in encode decode ascii
UserTag base64 attrAlias in file_in
UserTag base64 attrAlias out file_out
UserTag base64 HasEndTag
UserTag base64 Routine <<EOR
use MIME::Base64;
sub {
my $file_in = shift(@_) ||
undef;
my $file_out = shift(@_) || undef;
my $cgi_in = shift(@_) ||
undef;
my $encode = shift(@_) ||
0;
my $decode = shift(@_) ||
0;
my $ascii = shift(@_) ||
0;
my $debug_intype = 'content';
my $content = join("", @_);
my $output = '';
return 'Encode/Decode not specified' if ($encode == $decode);
if ($file_in) {
$debug_intype = 'file';
local $/ = undef unless ($ascii);
open(DATA, '<'.$file_in) || return 'Could not read file
'.$file_in.': '.$!;
binmode(DATA) unless ($ascii);
$content = <DATA>;
close(DATA);
}
elsif ($cgi_in) {
$debug_intype = 'cgi';
$content = $Tag->value_extended(
$cgi_in,
{
file_contents => 1,
joiner => '',
},
);
}
#
# encode data to base64
#
if ($encode == 1) {
$output =
MIME::Base64::encode_base64($content);
}
#
# decode base64 data
#
else {
$output =
MIME::Base64::decode_base64($content);
}
return $output if (!$file_out);
local $/ = undef unless ($ascii);
open(OUTPUT, '>'.$file_out);
binmode(OUTPUT) unless ($ascii);
print OUTPUT $output;
close(OUTPUT);
return '';
}
EOR
--snap--
Regards,
Lars
More information about the interchange-users
mailing list