GitHub

This library (and command-line utility) implement generic bidirectional Base91 encoding & decoding following the specification.

The codebase should be considered stable; it is documented using haddock and tested using QuickCheck.

Base91 is a scheme that allows arbitrary binary data (a sequence of 8-bit bytes, or octets) to be represented using an alphabet consisting of 91 of the 95 printable ASCII characters. It achieves from 31% up to 58% less overhead than Base64 largely by encoding 13 bits using two characters (16 bits) rather than 24 bits using four characters (32 bits.)

'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$',
'%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', '<', '=',
'>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '"'

The base91 package exposes a single generic Codec.Binary.Base91 module with two functions, the duals of each other:

(Note that because the functions' signatures are generic, in some cases an explicit output type must be provided; see the example.)

$ ghci Codec.Binary.Base91
λ let bytes = [72,101,108,108,111,44,32,119,111,114,108,100,33,10]
λ encode bytes :: String -- equal to "Hello, World!\n"
">OwJh>}A\"=r@@Y?FF"
λ decode ">OwJh>}A\"=r@@Y?FF" :: [Word8]
[72,101,108,108,111,44,32,119,111,114,108,100,33,10]
$ echo "Hello, World!" | base91 --encode
>OwJh>}AQ;r@@Y?FF
$ echo ">OwJh>}AQ;r@@Y?FF" | base91 --decode
Hello, World!

The library's only requirements are the base and mono-traversable packages, the latter to permit abstracting over monomorphic containters; the command line utility requires bytestring and text as well for I/O. Testing requires all the aforementioned plus the QuickCheck package. (See base91.cabal for details.)

Read the original on github.com ↗