Summary
Expose standard padded Base64 encoding as a small pure pf.Base64 module:
import pf.Base64
encoded = Base64.encode(bytes)
with an initial API of:
Motivation
While adding a multimodal outbound HTTP request to a basic-webserver
application, I needed to embed JPEG bytes in a JSON data URL:
image_url = "data:image/jpeg;base64,${Base64.encode(image)}"
The application currently has to carry its own Base64 implementation.
This need already exists inside basic-webserver itself. The
form-file-upload.roc example
contains a private encoder so it can render an uploaded PNG as a data URL.
Extracting that implementation into the platform would remove the duplication
and make a common web protocol primitive available to applications.
Other common uses include Basic authentication, MIME/content-transfer
encoding, webhooks, and binary values in JSON APIs.
Proposed scope
- Add a pure
platform/Base64.roc module.
- Expose it from
platform/main.roc.
- Implement the RFC 4648 standard alphabet with
= padding.
- Document that the output is ASCII and accepts arbitrary bytes, not only
UTF-8 input.
- Replace the private implementation in
examples/form-file-upload.roc with
the exposed module.
- Test the RFC 4648 vectors, empty input, one- and two-byte tails, and
non-UTF-8 binary input.
This should require no hosted operation or ABI change.
Decoding, unpadded output, and the URL-safe alphabet can be separate follow-up
features when there is a concrete use case for their API and error contract.
Acceptance criteria
Summary
Expose standard padded Base64 encoding as a small pure
pf.Base64module:with an initial API of:
Motivation
While adding a multimodal outbound HTTP request to a
basic-webserverapplication, I needed to embed JPEG bytes in a JSON data URL:
The application currently has to carry its own Base64 implementation.
This need already exists inside
basic-webserveritself. Theform-file-upload.rocexamplecontains a private encoder so it can render an uploaded PNG as a data URL.
Extracting that implementation into the platform would remove the duplication
and make a common web protocol primitive available to applications.
Other common uses include Basic authentication, MIME/content-transfer
encoding, webhooks, and binary values in JSON APIs.
Proposed scope
platform/Base64.rocmodule.platform/main.roc.=padding.UTF-8 input.
examples/form-file-upload.rocwiththe exposed module.
non-UTF-8 binary input.
This should require no hosted operation or ABI change.
Decoding, unpadded output, and the URL-safe alphabet can be separate follow-up
features when there is a concrete use case for their API and error contract.
Acceptance criteria
pf.Base64and encodeList(U8)as standardpadded Base64.
binary input.
private encoder.
encoding contract.