Expand description
Heap-free, panic-free, streaming multipart/form-data parser and encoder for
#![no_std].
The crate is sans-IO: you feed bytes to Parser::parse and get back at most
one Event per call plus the number of bytes consumed. Part data is yielded
as sub-slices of your own input buffer (zero-copy). Only part headers are
copied, into a line buffer whose size is the const generic LINE.
The normative specification is DESIGN.md in the repository; the rule numbers
referenced in the source (rule 3, …) point there.
use nostd_multipart::{Event, Parser};
let body = b"--xyz\r\nContent-Disposition: form-data; name=\"f\"\r\n\r\nhello\r\n--xyz--";
let mut p: Parser<'_> = Parser::new(b"xyz").unwrap();
let mut pos = 0;
let mut data = Vec::new();
loop {
let (used, ev) = p.parse(&body[pos..], true).unwrap();
pos += used;
match ev {
Some(Event::Data(d)) => data.extend_from_slice(d),
Some(Event::Finished) => break,
_ => {}
}
}
assert_eq!(data, b"hello");Structs§
- Content
Disposition - A parsed
Content-Dispositionheader value. - Decoded
- Iterator over the decoded bytes of a
ParamValue. - Encoder
- Streaming
multipart/form-dataencoder. - Multipart
Reader - Drives a
Parserfrom a blockingembedded_io::Readwith aBUF-byte buffer (BUF >= parser.min_buffer()). - Multipart
Reader Async - Drives a
Parserfrom anembedded_io_async::Readwith aBUF-byte buffer (BUF >= parser.min_buffer()). - Param
Value - A parameter value: the raw bytes plus lazy decoding of RFC 822 quoted-pairs
(
\x→x) and the WHATWG escapes%22,%0D,%0A(→", CR, LF). Other%sequences are left as they are. - Parser
- Streaming, zero-copy
multipart/form-dataparser. - Part
- Description of one part for the
Encoder.
Enums§
- Error
- Every failure the crate can report. See
DESIGN.md§12. - Event
- One parse event.
'iis the lifetime of theinputslice passed toParser::parse,'pthe borrow of the parser. - Read
Error - Error of the reader adapters.
Constants§
- MAX_
PADDING - Maximum number of SP/HTAB transport-padding bytes accepted between the boundary and the CRLF of a part delimiter (rule 3). More padding means “not a delimiter”.
Functions§
- boundary_
from_ random - Maps
Nrandom bytes (e.g. from a hardware RNG) to a valid boundary ofNbchars fromA–Z a–z 0–9 - _(6 bits of entropy per byte). - content_
disposition - Parses a
Content-Dispositionheader value (rule 8).