multipartkit/encoder

Values

pub fn encode(
  boundary: String,
  parts: List(part.Part),
) -> BitArray

Encode parts using the supplied boundary.

The boundary must satisfy the RFC 2046 grammar; otherwise the resulting message will be invalid. To keep this function pure and total, the encoder does not validate the boundary.

pub fn encode_form(the_form: form.Form) -> #(String, BitArray)

Encode a Form and return #(content_type, body).

content_type is the full value to set on the HTTP Content-Type header — for example multipart/form-data; boundary=----abc123. The boundary is generated freshly per call. Two calls on the same Form therefore produce different content_type values.

Note: v0.1.0 uses gleam/int.random for boundary character generation. This is sufficient for collision avoidance with normal payloads but is not cryptographically strong; do not rely on the boundary for security invariants.

pub fn encode_stream(
  boundary: String,
  parts: yielder.Yielder(stream.StreamPart),
) -> yielder.Yielder(Result(BitArray, error.MultipartError))

Encode a stream of StreamParts into a yielder of byte chunks.

Errors propagated from a StreamPart’s body iterator are forwarded as Error(_). After the first error, the yielder is exhausted.

Search Document