readSync method

  1. @override
Uint8List readSync(
  1. int count
)
override

Synchronously reads up to count bytes from a file

May return fewer than count bytes. This can happen, for example, when reading past the end of a file or when reading from a pipe that does not currently contain additional data.

An empty Uint8List will only be returned when reading past the end of the file or when count is 0.

Throws a FileSystemException if the operation fails.

Implementation

@override
Uint8List readSync(int count) {
  _assertIsOpen();
  _assertIsReadable('readSync');
  final int end = math.min(_position + count, lengthSync());
  final copy = _file.bytes.sublist(_position, end);
  _position = end;
  return Uint8List.fromList(copy);
}