MIME::...URLSafe(3pm)
π MIME::Base64::URLSafe π
okay bestie, so this page is from the User Contributed Perl Documentation collection, and it's about MIME::Base64::URLSafe β the module that does the URL-safe base64 thing. Pull up a chair, we're decoding this together π
β¨ NAME β¨
MIME::Base64::URLSafe β it's the Perl version of Python's URL-safe base64 codec. literally a whole port, and it ate π
πΈ SYNOPSIS πΈ
here's the vibe, short and sweet:
use MIME::Base64::URLSafe;
$encoded = urlsafe_b64encode('Alladdin: open sesame');
$decoded = urlsafe_b64decode($encoded);
that's it. that's the whole flex β¨
π¦ DESCRIPTION π¦
so, real talk: this module is a perl version of python's URL-safe base64 encoder / decoder. no cap, that's the whole job.
when you're embedding binary data in a URL, it is preferable to use base64 encoding. sounds great, right? except β the two characters '+' and '/' used in the standard base64 encoding have special meanings in URLs, and that often leads to re-encoding with URL-encoding, or worse, interoperability problems π it's giving chaos.
to overcome the problem, the module provides a variation of base64 codec compatible with python's urlsafe_b64encode / urlsafe_b64decode. iconic behaviour, honestly π«Ά
here's what gets modified from base64:
use '-' and '_' instead of '+' and '/'
no line feeds
no trailing equals (=)
bestie look closely at that list β'-'and'_'come in,'+'and'/''go out, the line feeds are gone, and the trailing=is gone too. periodt.
the following functions are provided:
urlsafe_b64encode($str)
urlsafe_b64decode($str)
and if you prefer not to import these routines to your namespace β totally valid, no pressure β you can call them as:
use MIME::Base64::URLSafe ();
$encoded = MIME::Base64::URLSafe::encode($decoded);
$decoded = MIME::Base64::URLSafe::decode($encoded);
iykyk π
π SEE ALSO π
MIME::Base64
fore more discussion on using base64 encoding in URL applications, see: http://en.wikipedia.org/wiki/Base64#URL_Applications
π AUTHOR π
Kazuho Oku <kazuho ___at___ labs.cybozu.co.jp>
Copyright (C) 2006 Cybozu Labs, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.
and that's the whole page, bestie β this one's from perl v5.36.0, dated 2022-11-27, and yeah the title up top really does say MIME::...URLSafe(3pm) because manpage headers love a little abbreviation moment π go forth and encode urlsafely, you've got this πβ¨ππ¦πΈπ
π¦ where this page comes from
- debian bookworm: libmime-base64-urlsafe-perl 0.01-5 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- debian trixie: libmime-base64-urlsafe-perl 0.01-5 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu noble: libmime-base64-urlsafe-perl 0.01-5 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu resolute: libmime-base64-urlsafe-perl 0.01-5 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu stonking: libmime-base64-urlsafe-perl 0.01-5 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms