#multipart #zero-allocation #streaming #http #async #reader-writer

multipart-rs

A simple, zero-allocation, streaming, async multipart reader & writer for Rust

9 releases

0.1.8 Mar 6, 2024
0.1.7 Mar 6, 2024

#9 in #zero-allocation

Download history 108/week @ 2024-02-25 563/week @ 2024-03-03 198/week @ 2024-03-10 6/week @ 2024-03-17 66/week @ 2024-03-31

301 downloads per month

MIT license

16KB
324 lines

Multipart-RS

A simple, zero-allocation, streaming, async multipart reader & writer for Rust

Reading multipart

let headermap = vec![(
    "Content-Type".to_string(),
    "multipart/form-data; boundary=--974767299852498929531610575".to_string(),
)];
// Lines must end with CRLF
let data = b"--974767299852498929531610575\r
Content-Disposition: form-data; name=\"afile\"; filename=\"a.txt\"\r
\r
Content of a.txt.\r
--974767299852498929531610575\r
Content-Disposition: form-data; name=\"bfile\"; filename=\"b.txt\"\r
Content-Type: text/plain\r
\r
Content of b.txt.\r
--974767299852498929531610575--\r\n";

let reader = MultipartReader::from_data_with_headers(data, &headermap);

loop {
    match reader.next().await {
        Some(Ok(item)) => println!(item),
        Some(Err(e)) => panic!("Error: {:?}", e),
        None => break,
    }
}

Dependencies

~0.9–1.2MB
~22K SLoC