Showcase

Try it on your own bytes.

Every demo below runs the real library, compiled from MoonBit to JavaScript, in this page. Nothing is faked in the browser.

Filename and MIME, both ways

A name implies a type; a type implies the extension people use. The same table answers both.

…
…
try:

Paste a multipart body

Drop in a body a browser or mail client would send. See each part, its Content-Disposition, and the form it makes.

…
What you are seeingmultipart splits the bytes at the boundary and parses each part's Content-Disposition. formdata reads the same bytes as a form: parts with a filename become files, the rest become fields. The chips above the parts are that second read.

Build a form, byte by byte

The other direction. Form::encode frames the parts, picks a boundary it has proven absent from them, and writes the Content-Type that carries it.

…
body
…
What you are seeingThe octets come from Form::encode; the chips are formdata reading those same octets back. Every break is a CRLF, the boundary stands in the header and in the body, and a file name that leaves ASCII goes out as filename* (RFC 5987).

Read it as it arrives

The same body, handed to the reader a piece at a time. Each part's headers come first; its body follows in whatever chunks the source gives. Nothing is read before it is needed.

…
What you are seeingEach chip is one piece the source handed over: the boxes are what the reader got, split where the chunks split. The count above them is how much of the body had to be pulled to see every part — the reader asks for a piece only when it needs the octets in it, so a part it stopped reading would cost less.