Skip to content

Conversation

xikaos
Copy link

@xikaos xikaos commented Sep 13, 2025

Issue

#863

Summary

Add base32 encode/decode to gleam/bit_array to complement existing base16/base64 (RFC 4648).

Works on Erlang and JavaScript targets.

Changes

Public API

  • base32_encode(input: BitArray, padding: Bool) -> String
  • base32_decode(encoded: String) -> Result(BitArray, Nil)

FFI

Erlang: base_encode32/2, base_decode32/1
JavaScript: encode32(bit_array, padding), decode32(s)

Tests

base32_encode_test and base32_decode_test (RFC 4648 vectors, partial-bit, lowercase acceptance, invalid inputs)

Behavior

  • Alphabet: A–Z, 2–7 (RFC 4648)
  • Encoding: optional = padding; pads bit arrays to full bytes
  • Decoding: accepts upper/lowercase and missing padding; rejects invalid chars and interior =

Notes

  • No breaking changes; naming aligns with existing base encoders.
  • All tests pass on Erlang and JavaScript (Deno) targets.

Additional Notes

  • This is my first significant Gleam contribution, please feel free to provide feedback and let me know about any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant