Expand description
Streaming response body support.
This module provides helpers for streaming large response bodies with:
- Memory-bounded buffering: Configurable chunk sizes to control memory usage
- Cancel-aware streaming: Integration with asupersync Cx for graceful cancellation
- File streaming: Efficient file streaming without loading entire files into memory
- Backpressure: Works with asupersync’s checkpoint system
§Example
ⓘ
use fastapi_http::streaming::{FileStream, StreamConfig};
use fastapi_core::{Response, ResponseBody};
async fn stream_file(cx: &Cx) -> Response {
let config = StreamConfig::default();
let stream = FileStream::open("large_file.bin", cx.clone(), config).await?;
Response::ok()
.header("content-type", b"application/octet-stream".to_vec())
.body(ResponseBody::stream(stream))
}Structs§
- Cancel
Aware Stream - A stream that wraps another stream and respects cancellation via Cx.
- Chunked
Bytes - A stream that yields chunks from an in-memory buffer.
- File
Stream - A stream that reads a file in chunks.
- Stream
Config - Configuration for streaming responses.
Enums§
- Stream
Error - Error types for streaming operations.
Constants§
- DEFAULT_
CHUNK_ SIZE - Default chunk size for streaming (64KB).
- DEFAULT_
MAX_ BUFFER_ SIZE - Default maximum buffer size (4MB).
Traits§
- Streaming
Response Ext - Extension trait for creating streaming response bodies.