sandi-0.2.3: Data encoding library

Safe HaskellNone



Implementation based on the specification found at



y_enc :: ByteString -> (ByteString, ByteString)Source

Encoding function.

This function allocates enough space to hold 20% more than the size of the indata (or at least 512 bytes) and then encodes as much as possible of the indata. That means there is a risk that the encoded data won't fit and in that case the second part of the pair contains the remainder of the indata.

>>> y_enc $ Data.ByteString.Char8.pack "foobar"
>>> snd $ y_enc $ Data.ByteString.Char8.pack $ Data.List.take 257 $ repeat '\x13'

y_dec :: ByteString -> Either (ByteString, ByteString) (ByteString, ByteString)Source

Decoding function.

>>> y_dec $ Data.ByteString.pack [144,153,153,140,139,156]
Right ("foobar","")
>>> y_dec $ Data.ByteString.Char8.pack "=}"
Right ("\DC3","")

A Left value is only ever returned on decoding errors which, due to characteristics of the encoding, can never happen.

>>> y_dec $ Data.ByteString.Char8.pack "="
Right ("","=")

encode :: ByteString -> ByteStringSource

Convenient function that calls y_enc repeatedly until the whole input data is encoded.