Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MIME::Base64

Native Rust implementation built into the interpreter. Runtime: PP. See original documentation for the full Perl reference.

Provides base64 encoding and decoding functions compatible with Perl’s MIME::Base64 module. Since PetaPerl does not support XS, this module is implemented directly in Rust.

Synopsis

use MIME::Base64;
my $encoded = encode_base64("Hello, World!");
my $decoded = decode_base64($encoded);
# Suppress line breaks
my $oneline = encode_base64($data, "");
# URL-safe variant
use MIME::Base64 'encode_base64url';
my $token = encode_base64url($data);

Functions

decode_base64

Decode a base64-encoded string back to the original binary data. Whitespace in the input is silently ignored.

use MIME::Base64;
my $decoded = decode_base64("SGVsbG8sIFdvcmxkIQ==");

decode_base64url

Decode a URL-safe base64-encoded string back to binary data.

use MIME::Base64 'decode_base64url';
my $data = decode_base64url($token);

decoded_base64_length

Return the length of the data that decode_base64 would produce for the given encoded string, without actually decoding it.

encode_base64

Encode binary data to base64. An optional second argument specifies the end-of-line sequence inserted every 76 characters (default: “\n”). Pass “” to suppress line breaks.

use MIME::Base64;
my $encoded = encode_base64("Hello, World!");
my $oneline = encode_base64($data, "");

encode_base64url

Encode binary data using the URL-safe base64 alphabet (- and _ instead of + and /), without padding or line breaks.

use MIME::Base64 'encode_base64url';
my $token = encode_base64url($data);

encoded_base64_length

Return the length of the string that encode_base64 would produce for the given data, without actually encoding it.