fileIterator function
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,
);