Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fill in README and minor test change

  • Loading branch information...
commit 1f00816633d0665c157749cfac1656036f21280d 1 parent c253483
@ronaldxs authored
Showing with 40 additions and 3 deletions.
  1. +38 −1 README.md
  2. +2 −2 t/long_line_and_encoding_cases.t
View
39 README.md
@@ -1,4 +1,41 @@
perl6-MIME-Base64
=================
-MIME Base64 encoding for Perl6 that understands Base64 is an encoding for binary data.
+
+# Synopsis
+
+```perl
+use PP::MIME::Base64;
+
+my $http_auth_send = encode_base64_str('Aladdin:open sesame');
+my $http_auth_recv = decode_base64_str('QWxhZGRpbjpvcGVuIHNlc2FtZQ==');
+
+my Buf $camelia_ico = slurp(
+ $?FILE.path.directory ~ '/data/camelia-favicon.ico', :bin
+);
+my $camelia_ico_b64 = encode_base64($camelia_ico);
+
+if decode_base64($camelia_ico_b64) eq $camelia_ico {
+ say 'Reconstituted icon ok'
+}
+
+```
+
+# Functions
+
+## `encode_base64(Buf $b, Str eol = "\n")`
+
+MIME/Base64 encode a Buf of arbitrary binary data. Return value is a Str. By default breaks up encoding with newline every 76 characters. To override line breakup pass empty string '' as second parameter.
+
+
+## `decode_base64(Str $b64)`
+
+Decode a string with MIME/Base64 encoded data into a Buf
+
+## `encode_base64_str(Str $s, Str $e = 'utf-8', :eol = "\n")`
+
+To make a common case easy this routine Mime/Base64 encodes a string for you. The result can vary based on your chosen string byte encoding eg utf-8(default) or iso-8859-1/latin-1 or ascii.
+
+## `decode_base64_str(Str $s, Str $d = 'utf-8')`
+To make another common case easy this routine takes a MIME/Base64 encoded string and, after decoding the Base64 into a byte stream Buf, returns a string based on the provided byte stream encoding which defaults to utf-8.
View
4 t/long_line_and_encoding_cases.t
@@ -23,7 +23,7 @@ biBpbnRvIG11bHRpcGxlIGxpbmVzIGFzIHJlcXVpcmVkIGJ5IE1JTUUu"),
'Decode Break up long line test';
my $screen_w_accent_e = chr(233) ~ "cran";
-is encode_base64_str($screen_w_accent_e, 'latin-1'), '6WNyYW4=', 'latin-1 string encoding test';
-is decode_base64_str('6WNyYW4=', 'latin-1'), $screen_w_accent_e, 'latin-1 string decoding test';
+is encode_base64_str($screen_w_accent_e, 'iso-8859-1'), '6WNyYW4=', 'latin-1 string encoding test';
+is decode_base64_str('6WNyYW4=', 'iso-8859-1'), $screen_w_accent_e, 'latin-1 string decoding test';
is encode_base64_str($screen_w_accent_e), 'w6ljcmFu', 'utf-8 string encoding test';
is decode_base64_str('w6ljcmFu'), $screen_w_accent_e, 'utf-8 string decoding test';
Please sign in to comment.
Something went wrong with that request. Please try again.