File::Raw · File::Raw::Base64 0.05
File::Raw::Base64
Base64 and base64url, PEM included, as File::Raw plugins.
Encoded files read as their bytes and bytes written encoded: standard and URL-safe alphabets, wrapped lines, padding on or off, and PEM's BEGIN and END lines handled on the way in and out.
Registers base64base64url
use File::Raw ();
use File::Raw::Base64;
my $bytes = File::Raw::slurp('token.b64', plugin => 'base64');
File::Raw::spew('blob.b64', $bytes, plugin => 'base64', wrap => 64);
# PEM: the BEGIN/END lines go on the way in, come back on the way out.
File::Raw::spew('cert.pem', $bytes,
plugin => 'base64', pem => 1, pem_label => 'CERTIFICATE');
my $der = File::Raw::slurp('cert.pem', plugin => 'base64', pem => 1);
What you get
-
Two alphabets
base64, andbase64urlwith-and_for tokens and URLs. -
PEM
pem => 1strips the BEGIN and END lines on read and writes them, with yourpem_label, on write. -
Wrapped or not
wrap => 64for PEM,76for MIME, or one line, andpaddingon or off.
The numbers
Against the fastest alternative that was installed, and shown whichever way it went.
- 2.0x read a base64 file holding 1 MB of bytes, against MIME::Base64 File::Raw::Base64 0.05 at 2410/s, MIME::Base64 3.16_01 at 1188/s
- 1.7x write 1 MB of bytes as base64, 76 a line, against MIME::Base64 File::Raw::Base64 0.05 at 2404/s, MIME::Base64 3.16_01 at 1381/s
Measured on Apple M5, darwin with perl 5.42.0, 2026-10-19: each entry timed for 3 CPU seconds by the Benchmark module, 3 times, the median kept, after checking that both sides produced the same result. Every number.
Works with
Chains from its documentation: the plugins run left to right on a read, right to left on a write.
plugin => ['base64', 'csv']with File::Raw::Separated