13 Base 64: Encoding and Decoding

▼ |  | Net: Networking Libraries

1 | HTTP Client
2 | URLs and HTTP
3 | URI Codec: Encoding and Decoding URIs
4 | FTP: Client
5 | Send URL: Opening a Web Browser
6 | SMTP: Sending E-Mail
7 | sendmail: Sending E-Mail
8 | Headers: Parsing and Constructing
9 | Header Field Encoding
10 | IMAP: Reading Mail
11 | POP3: Reading Mail
12 | MIME: Decoding Internet Data
13 | Base 64: Encoding and Decoding
14 | Quoted-Printable: Encoding and Decoding
15 | DNS: Domain Name Service Queries
16 | NNTP: Newsgroup Protocol
17 | TCP: Unit and Signature
18 | TCP Redirect: tcp^ via Channels
19 | SSL Unit: tcp^ via SSL
20 | CGI Scripts
21 | Cookie: Legacy HTTP Client Storage
22 | Git Repository Checkout
| Bibliography
| Index

► | 13 | Base 64: Encoding and Decoding

13.1 | Functions
13.2 | Base64 Unit
13.3 | Base64 Signature

On this page:

13.1`` Functions
base64-encode
base64-decode
base64-encode-stream
base64-decode-stream
13.2`` Base64 Unit
base64@
13.3`` Base64 Signature
base64^

top contents ← prev up next →

### 13`` Base 64: Encoding and Decoding🔗ℹ

(require net/base64) | package: base

The net/base64 library provides utilities for Base 64 (MIME-standard) encoding and decoding.

#### 13.1`` Functions🔗ℹ

> procedure (base64-encode bstr [newline]) → bytes?
> bstr : bytes?
> newline : any/c = #"\r\n"

Consumes a byte string and returns its Base 64 encoding as a new byte string. The returned string is broken into 72-byte lines separated by newline, which defaults to a CRLF combination, and the result always ends with a newline unless the input is empty.

Although newline is intended to be a byte string, it can be any value (possibly with a performance penalty), and it is converted to a byte string using display.

> procedure (base64-decode bstr) → bytes?
> bstr : bytes?

Consumes a byte string and returns its Base 64 decoding as a new byte string.

> procedure (base64-encode-stream in out [newline]) → void?
> in : input-port?
> out : output-port?
> newline : any/c = #"\n"

Reads bytes from in and writes the encoded result to out, breaking the output into 72-character lines separated by newline, and ending with newline unless the input stream is empty. Note that the default newline is just #"\n", not #"\r\n". The procedure returns when it encounters an end-of-file from in.

Although newline is intended to be a byte string, it can be any value, and it is written using display.

> procedure (base64-decode-stream in out) → void?
> in : input-port?
> out : output-port?

Reads a Base 64 encoding from in and writes the decoded result to out. The procedure returns when it encounters an end-of-file or Base 64 terminator = from in.

#### 13.2`` Base64 Unit🔗ℹ

> > > base64@ and base64^ are deprecated. They exist for backward-compatibility and will likely be removed in the future. New code should use the net/base64 module.

(require net/base64-unit) | package: compatibility-lib

> value base64@ : unit?

Imports nothing, exports base64^.

#### 13.3`` Base64 Signature🔗ℹ

(require net/base64-sig) | package: compatibility-lib

> signature base64^ : signature

Includes everything exported by the net/base64 module.

top contents ← prev up next →