std.base64
Base64 encoding and decoding.
This module provides types and methods for encoding and decoding base64 data.
Data is encoded using the Encoder type, while decoding is done using the
Decoder type.
The encoder and decoder implementations are based on the base64 encoder/decoder as found in Google Chrome, which is based on the code found in https://github.com/client9/stringencoders.
Examples
Encoding using the Encoder type, and decoding using the Decoder type:
import std.base64 (Decoder, Encoder)
let base64 = ByteArray.new
let plain = ByteArray.new
Encoder.new.encode('hello world'.to_byte_array, into: base64)
base64.to_string # => 'aGVsbG8gd29ybGQ='
Decoder.new.decode(base64, into: plain) # => Result.Ok(nil)
plain.into_string # => 'hello world'
For simple cases you can also use the encode and decode methods:
import std.base64 (decode, encode)
decode(encode('hello world'.to_byte_array))
.or_panic('failed to decode the input')
.to_string # => 'hello world'
Methods
| decode | Decodes a base64 encoded | |
| encode | Encodes a |
Classes
| DecodeError | An error produced when decoding a base64 encoded sequence of bytes. | |
| Decoder | A type for decoding a base64 encoded sequence of bytes into a raw sequence of bytes. | |
| Encoder | A type for encoding raw input as a base64 sequence of bytes. |