readBoundedFileSnapshot function

Future<Uint8List> readBoundedFileSnapshot(
  1. File file, {
  2. required int maxBytes,
})

Reads at most maxBytes from one stream-backed file snapshot.

The stream requests exactly one extra byte so growth after an earlier directory listing or stat cannot turn into an unbounded allocation.

Implementation

Future<Uint8List> readBoundedFileSnapshot(File file, {required int maxBytes}) {
  if (maxBytes < 0) {
    throw ArgumentError.value(maxBytes, 'maxBytes', 'must not be negative');
  }
  return readBoundedByteStreamSnapshot(
    file.openRead(0, maxBytes + 1),
    resourcePath: file.path,
    maxBytes: maxBytes,
  );
}