base64: RFC 4648-compliant padded and unpadded base64 and base64url encodings

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

RFC 4648-compliant padded and unpadded base64 and base64url encoding and decoding.

[Skip to Readme]


Versions,,,,,,, 0.4.0, 0.4.1, 0.4.2,,,,
Change log
Dependencies base (>=4.9 && <5), bytestring, deepseq, lens (>=4.18 && <4.19), text [details]
License BSD-3-Clause
Copyright (c) 2019 Emily Pillmore
Author Emily Pillmore
Category Data
Home page
Bug tracker
Source repo head: git clone
Uploaded by topos at 2020-01-05T02:33:27Z


[Index] [Quick Jump]


Manual Flags


Enable optics for base64-encoding text and bytestrings


Performance tuning flags and information


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Readme for base64-

[back to package description]


Build Status

Padded and unpadded base64 and base64url encodings for Text and ByteString values, along with their optics.


Haskell has two main libraries for Base64: memory, and base64-bytestring.

Of these, memory is geared towards integration with other memory primitives in the library, without much of an eye towards performance, while base64-bytestring is built to exclusively address ByteString encoding and decoding, and is very performant. Many great strides have been made in the realm of Base64 performance and vectorization just in the past 5 years, which this library attempts to capture. Additionally, we attempt to fix percieved shortcomings with both APIs in the support of unpadded Base64 and Base64-url support (which memory provides, but not base64-bytestring), as well as supporting Text values (neither libraries provide), and also supplying some nice compositional optics for composing structures with Base64-encodable/decodable focii (neither libraries provide).


Structs may want to support encoding and decoding their substructures, which is supported with the following prismatic typeclass:

class AsBase64 s where
    type Base64 s
    -- | A prism into a base64-encoded focus of
    -- some type
    _Base64 :: Prism' s (Base64 s)

    -- | A prism into the base64url-encoded focus of
    -- some type
    _Base64Url :: Prism' s (Base64 s)

The data of a Prism naturally conforms to this "encoding/decoding" dichotomy, where the Review, or "builder" half of the Prism of type b -> t is an encoding, and the "Matcher" half of the prism, of type s -> Either t a, represents a decoding of a similar structure. Monomorphizing for t ~ s and a ~ b, a simple Prism is formed:

>>> _Base64 @Text # "<<???>>"

>>> "PDw/Pz8+Pg==" ^? _Base64 @Text
Just "<<???>>"

The two most obvious types for which we have an instance are those that are supported natively by the library: ByteString and Text. Trivially, their instances consist of the functions provided here in this library.


What does this library provide? Here is the summary: