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

multipart-rs

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

13 releases

new 0.1.12 Nov 20, 2024
0.1.11 Jul 25, 2024
0.1.8 Mar 6, 2024

#748 in Web programming

Download history 340/week @ 2024-08-02 488/week @ 2024-08-09 1288/week @ 2024-08-16 1519/week @ 2024-08-23 1767/week @ 2024-08-30 1728/week @ 2024-09-06 1517/week @ 2024-09-13 1617/week @ 2024-09-20 1260/week @ 2024-09-27 1275/week @ 2024-10-04 1712/week @ 2024-10-11 1990/week @ 2024-10-18 1365/week @ 2024-10-25 1603/week @ 2024-11-01 1863/week @ 2024-11-08 1774/week @ 2024-11-15

6,934 downloads per month
Used in 12 crates (2 directly)

MIT license

20KB
397 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–1.4MB
~25K SLoC