#multipart #zero-allocation #http #streaming #async-stream #async #async-http

multipart-rs

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

16 releases

0.2.1 Nov 29, 2024
0.2.0 Nov 28, 2024
0.1.13 Nov 25, 2024
0.1.11 Jul 25, 2024
0.1.8 Mar 6, 2024

#234 in Web programming

Download history 1763/week @ 2024-12-15 2179/week @ 2024-12-22 2521/week @ 2024-12-29 1908/week @ 2025-01-05 1845/week @ 2025-01-12 1848/week @ 2025-01-19 1805/week @ 2025-01-26 2483/week @ 2025-02-02 2422/week @ 2025-02-09 1701/week @ 2025-02-16 1629/week @ 2025-02-23 1228/week @ 2025-03-02 1737/week @ 2025-03-09 3518/week @ 2025-03-16 2126/week @ 2025-03-23 2568/week @ 2025-03-30

10,159 downloads per month
Used in 3 crates

MIT license

21KB
442 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

~1.5MB
~26K SLoC