chunked_stream 1.1.0

Dart native js
Flutter Android iOS web

Utilities for working with chunked streams, such as byte streams which is often given as a stream of byte chunks with type `Stream<List<int>>`.

Chunked Stream Utilities #

Utilities for working with chunked streams, such as Stream<List<int>>.

Disclaimer: This is not an officially supported Google product.

A chunked stream is a stream where the data arrives in chunks. The most common example is a byte stream, which conventionally has the type Stream<List<int>>. We say a byte stream in chunked because bytes arrives in chunks, rather than individiually.

A byte stream could technically have the type Stream<int>, however, this would be very inefficient, as each byte would be passed as an individual event. Instead bytes arrives in chunks (List<int>) and the type of a byte stream is Stream<List<int>>.

To make it easy to work with the chunk streams, such as Stream<List<int>>, this package provides ChunkedStreamIterator which allows you to specify how many elements you want, and buffer unconsumed elements, making it easy to work with chunked streams one element at the time.

Example #

final reader = ChunkedStreamIterator(File('my-file.txt').openRead());
// While the reader has a next byte
while (true) {
  var data = await reader.read(1);  // read one byte
  if (data.length < 0) {
    print('End of file reached');
    break;
  }
  print('next byte: ${data[0]}');
}
10
likes
110
pub points
78%
popularity

Publisher

google.dev

Utilities for working with chunked streams, such as byte streams which is often given as a stream of byte chunks with type `Stream<List<int>>`.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache 2.0 (LICENSE)

More

Packages that depend on chunked_stream