chunked_stream library
Utilities for working with chunked streams.
This library provides the following utilities:
- ChunkedStreamIterator, for reading a chunked stream by iterating over chunks and splitting into substreams.
- readByteStream, for reading a byte stream into a single Uint8List. Often useful for converting Stream<List<int>> to Uint8List.
- readChunkedStream, for reading a chunked stream into a single big list.
- limitChunkedStream, for wrapping a chunked stream as a new stream with length limit, useful when accepting input streams from untrusted network.
- bufferChunkedStream, for buffering a chunked stream. This can be useful to improve I/O performance if reading the stream chunk by chunk with frequent pause/resume calls, as is the case when using ChunkedStreamIterator.
- asChunkedStream, for wrapping a Stream<T> as Stream<List<T>>, useful for batch processing elements from a stream.
Classes
-
ChunkedStreamIterator<
T> - Auxiliary class for iterating over the items in a chunked stream.
Extensions
-
ChunkedStreamIteratorByteStreamExt
on ChunkedStreamIterator<
int> - Extension methods for ChunkedStreamIterator when working with byte-streams Stream<List<int>>.
Functions
-
asChunkedStream<
T> (int N, Stream< T> input) → Stream<List< T> > -
Wrap
input
as a chunked stream with chunks the size ofN
. -
bufferChunkedStream<
T> (Stream< List< input, {int bufferSize = 16 * 1024}) → Stream<T> >List< T> > - Buffer an chunked stream.
-
limitChunkedStream<
T> (Stream< List< input, {int? maxSize}) → Stream<T> >List< T> > -
Create a chunked stream limited to the first
maxSize
items frominput
. -
readByteStream(
Stream< List< input, {int? maxSize}) → Future<int> >Uint8List> -
Read all bytes from
input
and return a Uint8List consisting of all bytes frominput
. -
readChunkedStream<
T> (Stream< List< input, {int? maxSize}) → Future<T> >List< T> > -
Read all chunks from
input
and return a list consisting of items from all chunks.
Exceptions / Errors
- MaximumSizeExceeded
- Exception thrown if maxSize was exceeded while reading a chunked stream.