Skip to content

aramiscd/gren-base64-bytes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Base64

Gren package for encoding and decoding Base64 strings.

This project is a Gren port of danfishgold/base64-bytes.

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.

Usage

gren package install aramiscd/gren-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

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

--> Just "Hello World"

About

convert between base64 strings and bytes

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages