On this page:
13.1 Functions
base64-encode
base64-decode
base64-encode-stream
base64-decode-stream
13.2 Base64 Unit
[email protected]
13.3 Base64 Signature
base64^

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-bstr])  bytes?

  bstr : bytes?
  newline-bstr : bytes? = #"\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-bstr, which defaults to a CRLF combination, and the result always ends with a newline-bstr unless the input is empty.

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-bstr])  void?

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

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

[email protected] 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

[email protected] : 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.