gb64
A high-performance, pure Perl implementation of Base64 encoding and decoding, compliant with RFC 4648.
Synopsis
use gb64 qw(enc_b64 dec_b64);
# Direct encoding/decoding
my $encoded = enc_b64("Hello World"); # Returns "SGVsbG8gV29ybGQ="
my $decoded = dec_b64($encoded); # Returns "Hello World"
# Streaming encoding/decoding
my $gb64 = gb64->new;
$gb64->add("Hello ")->add("World");
$encoded = $gb64->encode; # Returns "SGVsbG8gV29ybGQ="
Description
gb64 is a fast and lightweight Base64 encoding and decoding library in pure Perl, with no XS or C dependencies. It supports both one-shot encoding/decoding and streaming for large or incremental datasets. Optimized with unpack, pack, and array-based lookups, gb64 outperforms other pure Perl implementations like MIME::Base64::Perl by up to 97.7% for large inputs (110k bytes).
The module is compliant with RFC 4648, includes robust error handling, and is compatible with Perl 5.8.8 and later.
Features
- Fast pure Perl implementation with no external dependencies
- Compliant with RFC 4648 Base64 specification
- Functional interface for one-shot encoding/decoding
- Object-oriented streaming interface for large datasets
- Robust error handling for invalid inputs
- Up to 97.7% faster than MIME::Base64::Perl for large inputs
Installation
To install from CPAN:
cpan gb64
Or manually:
perl Makefile.PL
make
make test
make install
Dependencies
- Runtime: Core Perl modules (strict, warnings, Exporter)
- Testing: Test::More (>= 0.88), MIME::Base64
Testing
Run the test suite to verify functionality:
prove -v ./
The test suite includes functional, streaming, and error-handling tests, using MIME::Base64 as a reference implementation.
Performance
Benchmarks show gb64 achieves:
- Encoding: 26.4 iterations/second for large inputs (110k bytes)
- Decoding: 24.5 iterations/second for large inputs (110k bytes)
Compared to
MIME::Base64::Perl,gb64is up to 97.7% faster for large inputs (26.4/s vs. 1051/s for encoding, 24.5/s vs. 1049/s for decoding). For small inputs (~5 bytes), performance is comparable for encoding but slightly slower for decoding (-28.0%) due to robust validation. See benchmark.pl in the repository for details.
Author
OnEhIppY, Domero Software domerosoftware@gmail.com (mailto:domerosoftware@gmail.com)
Copyright and License
Copyright (C) 2025 by OnEhIppY, Domero Software This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either:
- The GNU General Public License, version 1 or later
- The Artistic License included with Perl
On Debian systems, see
/usr/share/common-licenses/GPLfor the GNU General Public License and/usr/share/common-licenses/Artisticfor the Artistic License.
Support
- Repository: https://github.com/DomeroSoftware/gb64
- Issues: https://github.com/DomeroSoftware/gb64/issues
- Email: domerosoftware@gmail.com (mailto:domerosoftware@gmail.com)
See Also
- RFC 4648 - The Base16, Base32, and Base64 Data Encodings
MIME::Base64- A faster XS-based Base64 implementationMIME::Base64::Perl- Another pure Perl Base64 implementation