Skip to content
Base64 conversion to and from bytes
Elm
Branch: master
Clone or download
Latest commit 7a8315c Aug 4, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Make the example prettier Dec 4, 2018
src Bump version Aug 3, 2019
tests Accept input lengths that are not multiples of 4 May 8, 2019
.gitignore Will I ever remember to use git from the start? Dec 3, 2018
CHANGELOG.md Bump version Aug 3, 2019
LICENSE Add license Dec 3, 2018
README.md Make the example prettier Dec 4, 2018
elm.json Bump version Aug 3, 2019

README.md

Base64

This is an Elm package for encoding and decoding Base64 strings.

You can read more about Base64 on Wikipedia, but basically you can use Base64 to encode bytes in plain text.

This package allows you to convert bytes to Base64 strings with Base64.fromBytes and convert a Base64 string to bytes with Base64.toBytes.

View demo

Usage

elm install danfishgold/base64-bytes

Bytes to Base64

import Bytes.Encode
import Base64

Bytes.Encode.string "Hello World"
    |> Bytes.Encode.encode
    |> Base64.fromBytes

--> Just "SGVsbG8gV29ybGQ="

Bytes.Encode.string "אהלן עולם"
    |> Bytes.Encode.encode
    |> Base64.fromBytes

--> Just "15DXlNec158g16LXldec150="

Base64 to Bytes

import Bytes
import Bytes.Decode
import Base64

case Base64.toBytes "SGVsbG8gV29ybGQ=" of
    Nothing ->
        Just "Invalid Base64 string"
    Just bytes ->
        Bytes.Decode.decode (Bytes.Decode.string (Bytes.width bytes)) bytes

--> Just "Hello World"

You can’t perform that action at this time.