fileIterator function

OffsetIterator<Uint8List> fileIterator(
  1. File file, {
  2. int blockSize = 64 * 1024,
  3. String name = 'fileIterator',
  4. bool cancelOnError = true,
})

Perform a streaming read operation on the given File. blockSize changes the amount of bytes to read into each chunk.

Implementation

OffsetIterator<Uint8List> fileIterator(
  File file, {
  int blockSize = 64 * 1024,
  String name = 'fileIterator',
  bool cancelOnError = true,
}) =>
    OffsetIterator(
      name: name,
      init: () => file.open(mode: FileMode.read),
      process: (acc) async {
        final file = acc as RandomAccessFile;
        final chunk = await file.read(blockSize);
        final hasMore = chunk.length == blockSize;

        return OffsetIteratorState(
          acc: file,
          chunk: [chunk],
          hasMore: hasMore,
        );
      },
      cleanup: (file) => file.close(),
      cancelOnError: cancelOnError,
    );