Permalink
Browse files

comments

  • Loading branch information...
1 parent 777c1c4 commit 6ccf545fb1a4be0f1e75a96180a25925399c02fb @ronaldxs committed Sep 11, 2012
Showing with 13 additions and 3 deletions.
  1. +11 −2 lib/PP/Enc/MIME/Base64.pm6
  2. +2 −1 t/binary.t
View
@@ -10,6 +10,7 @@ module PP::Enc::MIME::Base64:auth<ronaldxs>:ver<0.01> {
# that implementation here but note it for anyone considering
# a parrot or external library implementation
+ ######################################################################
our Str sub encode_base64(Buf $b, Str $eol = "\n") is export {
my Str $rc = '';
my Str $padding_suffix = '';
@@ -45,8 +46,10 @@ module PP::Enc::MIME::Base64:auth<ronaldxs>:ver<0.01> {
return $rc ~ $padding_suffix;
}
+ ######################################################################
# Greatly wondering whether building everything in a list of Int
# and then newing the Buf is the most efficient way
+ ######################################################################
our Buf sub decode_base64(Str $s) is export {
my Int @rc;
my Str $end_pad = ($s ~~ /\= ** 1..2\s*/).Str;
@@ -73,11 +76,17 @@ module PP::Enc::MIME::Base64:auth<ronaldxs>:ver<0.01> {
return Buf.new(@rc);
}
- our Str sub encode_base64_str(Str $s, Str $e = 'utf-8', :$eol = "\n") is export {
+ ######################################################################
+ our Str sub encode_base64_str(Str $s, Str $e = 'utf-8', :$eol = "\n")
+ is export
+ {
encode_base64($s.encode($e), $eol);
}
- our Str sub decode_base64_str(Str $s, Str $d = 'utf-8') is export {
+ ######################################################################
+ our Str sub decode_base64_str(Str $s, Str $d = 'utf-8')
+ is export
+ {
decode_base64($s).decode($d);
}
View
@@ -18,7 +18,8 @@ ok decode_base64('/w==') eq Buf.new(255), 'decode Test on byte value 255';
my Buf $camelia_ico = slurp(
$?FILE.path.directory ~ '/data/camelia-favicon.ico', :bin
);
-my Str $camelia_b64 = slurp(
+# .b64 file generated from .ico file with gnu base64 program
+my Str $camelia_b64 = slurp(
$?FILE.path.directory ~ '/data/camelia-favicon.b64'
);
is encode_base64($camelia_ico), $camelia_b64.chomp, 'binary img encode test';

0 comments on commit 6ccf545

Please sign in to comment.