On this page:
35.1 High-Level Interface
encode
decode
denxi-encodings
denxi-encoding/  c
encoded-file-name
35.2 UTF-8 Conversions
coerce-string
coerce-bytes
35.3 Abbreviated Decoding Procedures
abbreviated-decode-procedure/  c
hex
base64
base32
8.12

35 Codec🔗ℹ

 (require denxi/codec) package: denxi

The denxi/codec module encodes and decodes byte strings. Note that ports are not used, so all data sits entirely in memory.

35.1 High-Level Interface🔗ℹ

procedure

(encode encoding variant)  (or/c bytes? string?)

  encoding : denxi-encoding/c
  variant : (or/c bytes? string?)
Encodes a byte string or UTF-8 encoded string according to encoding. The return value type matches the type of variant.

procedure

(decode encoding encoded)  (or/c bytes? string?)

  encoding : denxi-encoding/c
  encoded : (or/c bytes? string?)
Decodes a byte string or UTF-8 encoded string according to encoding. The return value type matches the type of encoded.

A list of supported encodings of byte strings.

Bound to
  '(base64 base32 hex colon-separated-hex)

A contract that accepts a value in denxi-encodings.

procedure

(encoded-file-name variant)  path-string?

  variant : (or/c bytes? string?)
Returns up to the first 32 characters of (coerce-string (encode 'base32 variant)), which is suitable for use as a file name across platforms.

35.2 UTF-8 Conversions🔗ℹ

procedure

(coerce-string v)  string?

  v : (or/c string? bytes?)
Equivalent to

(if (string? v) v (bytes->string/utf-8 v))

procedure

(coerce-bytes v)  bytes?

  v : (or/c string? bytes?)
Equivalent to

(if (bytes? v) v (string->bytes/utf-8 v))

35.3 Abbreviated Decoding Procedures🔗ℹ

An abbreviated decoding procedure (or ADP) helps a user represent a byte string with a more convenient notation.

e.g.

(integrity 'sha384 (base64 "z/2YR1yTDC0YBvgQFpGUzXGtqZdPx+E//C2tyYNDENnLf7NGexuuDc/3yOhoGqBn"))

Decodes a hex-encoded string to bytes. The process is case-insensitive.

encoded may separate each pair of hex digits with ":".

This implies (equal? (hex "deadbeef") (hex "de:ad:be:ef")).

Decodes a Base64-encoded string to bytes.

Decodes a Base32-encoded string to bytes.