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

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

#751 in Web programming

Download history 1929/week @ 2024-08-21 1676/week @ 2024-08-28 1750/week @ 2024-09-04 1400/week @ 2024-09-11 1862/week @ 2024-09-18 1246/week @ 2024-09-25 1221/week @ 2024-10-02 1366/week @ 2024-10-09 2247/week @ 2024-10-16 1391/week @ 2024-10-23 1651/week @ 2024-10-30 1557/week @ 2024-11-06 1882/week @ 2024-11-13 2063/week @ 2024-11-20 2320/week @ 2024-11-27 2201/week @ 2024-12-04

8,769 downloads per month
Used in 12 crates (2 directly)

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
~25K SLoC