# std/base64

## Index

- type [`Base64`](#base64)
- type [`DecodeErr`](#decodeerr)
  - method [`DecodeErr.display`](#decodeerrdisplay)
- fn [`encode`](#encode)
- fn [`decode`](#decode)

## Types

### Base64

```xo
enum Base64 {
  Std
  Url
  RawStd
  RawUrl
}
```

RFC 4648 section 4 (`Std`, `+/`) and section 5 (`Url`, `-_`); the Raw
forms write and read no `=` padding.

[Source: `std/base64.xo:8`](https://github.com/xo-lang/xo/blob/main/std/base64.xo#L8)

### DecodeErr

```xo
struct DecodeErr {
  at: Int
}
```

Displays as Go's CorruptInputError: `illegal base64 data at input byte 4`.

[Source: `std/base64.xo:16`](https://github.com/xo-lang/xo/blob/main/std/base64.xo#L16)

#### DecodeErr.display

```xo
fn (e: DecodeErr) display() -> Str
```

[Source: `std/base64.xo:20`](https://github.com/xo-lang/xo/blob/main/std/base64.xo#L20)

## Functions

### encode

```xo
fn encode(data: Bytes, enc: Base64 = Base64.Std) -> Str
```

[Source: `std/base64.xo:22`](https://github.com/xo-lang/xo/blob/main/std/base64.xo#L22)

### decode

```xo
fn decode(s: Str, enc: Base64 = Base64.Std) -> Bytes ! DecodeErr
```

`\r` and `\n` are skipped; anything else outside the alphabet, or
padding where the encoding has none, is DecodeErr at its byte offset.

[Source: `std/base64.xo:25`](https://github.com/xo-lang/xo/blob/main/std/base64.xo#L25)

