ChunkTransformer<T> class
A StreamTransformer that splits incoming lists into smaller fixed-size chunks.
This transformer takes a stream of lists and emits sublists of at most chunkSize elements. Useful for processing or transmitting large lists in manageable parts, for example, when sending data over a network or writing to files in chunks.
The last chunk may be smaller than chunkSize if there are not enough remaining elements.
Example
final dataStream = Stream.value(List.generate(10000, (i) => i));
final chunkedStream = dataStream.transform(const ChunkTransformer<int>(chunkSize: 1024));
await for (final chunk in chunkedStream) {
print('Chunk with ${chunk.length} items');
}
See also:
- StreamTransformer, which is the base class for all stream transformations.
Stream.chunked
(extension in package:collection), which splits iterables into chunks.
- Implemented types
-
- StreamTransformerBase<
List< T> , List<T> >
- StreamTransformerBase<
Constructors
- ChunkTransformer({int chunkSize = 8192})
-
Creates a ChunkTransformer that emits sublists of at most
chunkSize
elements.const
Properties
Methods
-
bind(
Stream< List< stream) → Stream<T> >List< T> > -
Transforms the provided
stream
.override -
cast<
RS, RT> () → StreamTransformer< RS, RT> -
Provides a
StreamTransformer<RS, RT>
view of this stream transformer.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited