Codec.Binary.Yenc

sandi-0.4.0: Data encoding library

Copyright | (c) 2012 Magnus Therning
License | BSD3
Safe Haskell | None
Language | Haskell98

Codec.Binary.Yenc

Description

Implementation based on the specification found at http://yence.sourceforge.net/docs/protocol/version1_3_draft.html.

Synopsis

- yEncode :: ByteString -> (ByteString, ByteString)
- yDecode :: ByteString -> Either (ByteString, ByteString) (ByteString, ByteString)
- encode :: ByteString -> ByteString
- decode :: ByteString -> Either (ByteString, ByteString) ByteString

# Documentation

yEncode :: ByteString -> (ByteString, ByteString) #

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.

    >>> yEncode $ Data.ByteString.Char8.pack "foobar"
    ("\144\153\153\140\139\156","")
    >>> snd $ yEncode $ Data.ByteString.Char8.pack $ Data.List.take 257 $ repeat '\x13'
    "\DC3"

yDecode :: ByteString -> Either (ByteString, ByteString) (ByteString, ByteString) #

Decoding function.

    >>> yDecode $ Data.ByteString.pack [144,153,153,140,139,156]
    Right ("foobar","")
    >>> yDecode $ 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.

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

encode :: ByteString -> ByteString #

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

decode :: ByteString -> Either (ByteString, ByteString) ByteString #

A synonym for `y_dec`.