Expose standard Base64 encoding as a platform module

Aperta
#197 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla

Direzione di ricerca

Inizia leggendo l'encoder privato in examples/form-file-upload.roc e le esportazioni del modulo in platform/main.roc. Analizza come vengono testati e documentati i moduli della piattaforma, quindi usa quei punti di ingresso per definire platform/Base64.roc e la relativa copertura dei test per RFC 4648. Il lavoro è completato quando l'esempio importa pf.Base64, i test binari e dei casi limite passano e la documentazione API generata descrive il contratto di codifica.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement good first issue

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:

encode : List(U8) -> Str

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

  • Applications can import pf.Base64 and encode List(U8) as standard
    padded Base64.
  • The implementation matches RFC 4648 test vectors and handles arbitrary
    binary input.
  • The file-upload example uses the shared module instead of maintaining a
    private encoder.
  • The generated platform API documentation includes the module and its
    encoding contract.
Lingua principale
HTML
Stelle
110
Fork
25
Merge medio
18h 28m
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di roc-lang/basic-webserver

Tutte le issue di roc-lang/basic-webserver

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.