Expand description
A streaming multipart/form-data parser for Rust.
This crate provides a zero-copy (or minimal-copy) streaming parser for multipart data, optimized for performance and memory efficiency. It uses the lending iterator pattern to yield parts as they arrive, without buffering the entire input.
§Examples
use multipart_async_stream::{MultipartStream, LendingIterator};
use bytes::Bytes;
use futures_util::stream;
let data = b"--boundary\r\n\
Content-Disposition: form-data; name=\"field1\"\r\n\
\r\n\
value1\r\n\
--boundary--\r\n";
let stream = stream::iter(vec![Result::<Bytes, std::convert::Infallible>::Ok(Bytes::from(&data[..]))]);
let mut multipart = MultipartStream::new(stream, b"boundary");
while let Some(Ok(part)) = multipart.next().await {
let _headers = part.headers();
// Consume part.body() stream...
}§Safety Note
The returned Part holds a mutable reference to the underlying MultipartStream.
You must fully consume the part’s body stream before calling next()
again. Failing to do so will result in a BodyNotConsumed error.
Modules§
- header
- HTTP header types
Structs§
- Multipart
Stream - A streaming multipart/form-data parser.
- Next
Future - Future for the next part in the multipart stream.
- Part
- A single part in a multipart stream.
Enums§
- Error
- Errors that can occur during multipart parsing.
- Parse
Error - Errors that can occur during multipart header parsing.
Traits§
- Lending
Iterator - An interface for dealing with iterators which borrow from
Self - TryStream
- A convenience for streams that return
Resultvalues that includes a variety of adapters tailored to such futures. - TryStream
Ext - Adapters specific to
Result-returning streams