🟡 Streaming Utilities
Process response streams with powerful built-in utilities for real-time data handling.
Z-Fetch provides comprehensive streaming utilities that make it easy to work with response streams for real-time data processing, large file handling, and memory-efficient operations.
Available Streaming Methods
streamToString()- Convert stream to stringstreamToBlob()- Convert stream to Blob (files/media)streamToArrayBuffer()- Convert stream to ArrayBuffer (binary)streamChunks(callback)- Process chunks as they arrive
Automatic Resource Management
All streaming utilities include automatic resource cleanup and comprehensive error handling.
Basic Streaming
Stream to String
Perfect for text-based APIs and content:
Stream to Blob
Ideal for files, images, and media:
Stream to ArrayBuffer
For binary data processing:
Chunk Processing
Process data as it arrives for real-time applications:
Real-World Examples
Processing Large Datasets
Handle large datasets without loading everything into memory:
Real-Time Chat Messages
Stream live chat messages:
File Download with Progress
Combine streaming with progress tracking:
Server-Sent Events (SSE) Alternative
Use streaming for SSE-like functionality:
Error Handling
Comprehensive error handling for streaming operations:
Performance Tips
Memory Efficiency:
- Use
streamChunks()for large datasets to avoid loading everything into memory - Process data incrementally rather than buffering everything
- Clean up object URLs when done with blobs
Error Recovery:
- Implement chunk-level error handling to continue processing
- Provide fallbacks for when streaming fails
- Monitor memory usage for long-running streams
Real-Time Processing:
- Keep chunk processing functions lightweight
- Use requestAnimationFrame for UI updates
- Consider using Web Workers for heavy processing
Related Features
Streaming works seamlessly with other Z-Fetch features:
- ⭐ Progress Tracking - Monitor upload/download progress alongside streaming
- 🚨 Error Handling - Comprehensive error handling for streaming operations
- 💪 Using Hooks - Enhanced hooks system for request lifecycle management
- 👉 Request Methods - All HTTP methods support streaming capabilities