sandi-0.3.3: Data encoding library

Copyright(c) 2012 Magnus Therning
LicenseBSD3
Safe HaskellNone
LanguageHaskell98

Codec.Binary.QuotedPrintable

Description

Implementation of Quoted-Printable based on RFC 2045 (http://tools.ietf.org/html/rfc2045).

This encoding encodes everything that is passed in, it will not try to guess the native line ending for your architecture. In other words, if you are using this to encode text you need to split it into separate lines before encoding.

Synopsis

Documentation

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

Encoding function.

This function allocates enough space to hold twice 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.

>>> qp_enc $ Data.ByteString.Char8.pack "="
("=3D","")
>>> snd $ qp_enc $ Data.ByteString.Char8.pack $ Data.List.take 171 $ repeat '='
"="

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

Decoding function.

>>> qp_dec $ Data.ByteString.Char8.pack "foobar"
Right "foobar"
>>> qp_dec $ Data.ByteString.Char8.pack "1=20+=201=20=3D=202"
Right "1 + 1 = 2"

The input data is allowed to use lowercase letters in the hexadecimal representation of an octets value, even though the standard says that only uppercase letters may be used:

>>> qp_dec $ Data.ByteString.Char8.pack "=3D"
Right "="
>>> qp_dec $ Data.ByteString.Char8.pack "=3d"
Right "="

It also allows the input to encode _all_ octets in the hexadecimal representation:

>>> qp_dec $ Data.ByteString.Char8.pack "=20!"
Right (" !","")
>>> qp_dec $ Data.ByteString.Char8.pack "=20=21"
Right (" !","")

A Left value is only ever returned on decoding errors.

>>> qp_dec $ Data.ByteString.Char8.pack "=2"
Right ("","=2")
>>> qp_dec $ Data.ByteString.Char8.pack "=2g"
Left ("","=2g")

encode :: ByteString -> ByteString Source

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