memory-0.14.18: memory and related abstraction stuff

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Stability | experimental
Portability | unknown
Safe Haskell | None
Language | Haskell2010

Data.ByteArray.Encoding

Description

Base conversions for `ByteArray`.

Synopsis

- convertToBase :: (ByteArrayAccess bin, ByteArray bout) => Base -> bin -> bout
- convertFromBase :: (ByteArrayAccess bin, ByteArray bout) => Base -> bin -> Either String bout
- data Base
  - = Base16
  - | Base32
  - | Base64
  - | Base64URLUnpadded
  - | Base64OpenBSD

# Documentation

convertToBase :: (ByteArrayAccess bin, ByteArray bout) => Base -> bin -> bout #

Encode some bytes to the equivalent representation in a specific `Base`.

#### Examples

Convert a `ByteString` to base-64:

    >>> convertToBase Base64 ("foobar" :: ByteString) :: ByteString
    "Zm9vYmFy"

convertFromBase :: (ByteArrayAccess bin, ByteArray bout) => Base -> bin -> Either String bout #

Try to decode some bytes from the equivalent representation in a specific `Base`.

#### Examples

Successfully convert from base-64 to a `ByteString`:

    >>> convertFromBase Base64 ("Zm9vYmFy" :: ByteString) :: Either String ByteString
    Right "foobar"

Trying to decode invalid data will return an error string:

    >>> convertFromBase Base64 ("!!!" :: ByteString) :: Either String ByteString
    Left "base64: input: invalid length"

data Base #

The different bases that can be used.

See RFC4648 for details. In particular, Base64 can be standard or URL-safe. URL-safe encoding is often used in other specifications without padding characters.

#### Examples

A quick example to show the differences:

    >>> let input = "Is 3 > 2?" :: ByteString
    >>> let convertedTo base = convertToBase base input :: ByteString
    >>> convertedTo Base16
    "49732033203e20323f"
    >>> convertedTo Base32
    "JFZSAMZAHYQDEPY="
    >>> convertedTo Base64
    "SXMgMyA+IDI/"
    >>> convertedTo Base64URLUnpadded
    "SXMgMyA-IDI_"
    >>> convertedTo Base64OpenBSD
    "QVKeKw.8GBG9"

Constructors

Base16 | similar to hexadecimal
Base32 |
Base64 | standard Base64
Base64URLUnpadded | unpadded URL-safe Base64
Base64OpenBSD | Base64 as used in OpenBSD password encoding (such as bcrypt)

Instances

Eq Base # |
Instance details Defined in Data.ByteArray.Encoding Methods (==) :: Base -> Base -> Bool # (/=) :: Base -> Base -> Bool #
Show Base # |
Instance details Defined in Data.ByteArray.Encoding Methods showsPrec :: Int -> Base -> ShowS # show :: Base -> String # showList :: [Base] -> ShowS #