multipart-async-stream
A high-performance, zero-copy streaming multipart/form-data and multipart/byteranges parser for Rust.
Features
- Zero-copy parsing - Leverages
memchrfor efficient pattern matching - Streaming API - Process data incrementally without buffering the entire input
- Lending iterator pattern - Yields parts as they arrive using GATs
- Async-first - Built on
futureswithasync/awaitsupport - HTTP-compliant - Handles both
multipart/form-dataandmultipart/byteranges
Quick Start
use ;
use Bytes;
use ;
async
⚠️ Critical Usage Requirements
You MUST consume each part's body completely before requesting the next part
This is the most important rule when using this library:
- Each
Partholds a mutable borrow of the underlyingMultipartStream - The body must be fully consumed (until it returns
None) before the next call tonext() - Failure to comply will result in a
BodyNotConsumederror
❌ Wrong
let part1 = multipart.next.await.unwrap?;
// Don't do this! Trying to get the next part without consuming part1's body
let part2 = multipart.next.await; // Returns Err(BodyNotConsumed)
✅ Right
while let Some = multipart.next.await
Why This Requirement?
This library uses a lending iterator pattern where each Part mutably borrows the parser state. This design enables:
- Zero-copy operation - No unnecessary buffering of body data
- Constant memory usage - Memory usage stays O(1) regardless of part size
- Performance - Single-pass parsing with minimal allocations
The tradeoff is that you must consume parts sequentially. See RFC 2956 for details on lending iterators in Rust.
HTTP Range Request Example
use ;
async
Performance
- O(n) time complexity - Single pass through the input
- O(1) space complexity - Fixed buffer size regardless of input size
- Zero-copy - Body chunks are returned as views into the input buffer
- memchr-optimized - Uses SIMD-accelerated byte pattern matching
Fuzzing
This crate includes comprehensive fuzzing tests to ensure reliability and security:
# Run fuzz tests (3 hours by default - production-ready duration)
&&
# Quick test for development (5 minutes)
&&
# Standard test for PR validation (30 minutes)
&&
# Extended test for release candidates (6 hours)
&&
# Manual testing individual targets
Recommended Testing Durations:
- Development: 5 minutes - Quick smoke test during active development
- PR Validation: 30 minutes - Thorough testing before merging code changes
- Pre-release: 3 hours - Default duration for production releases
- Critical Updates: 6-24 hours - Extended testing for security or core parser changes
Results:
- ✅ No panics or crashes detected
- ✅ 1656+ code coverage achieved
- ✅ 3200+ exec/s execution speed
- ✅ Memory-safe with no leaks
See fuzz/README.md for documentation.
License
MIT OR Apache-2.0