FileBuffer constructor

FileBuffer(
  1. AbstractFileHandle file, {
  2. ByteOrder byteOrder = ByteOrder.littleEndian,
  3. int bufferSize = kDefaultBufferSize,
})

Create a FileBuffer with the given file. byteOrder determines if multi-byte values should be read in bigEndian or littleEndian order. bufferSize controls the size of the buffer to use for file IO caching. The larger the buffer, the less it will have to access the file system.

Implementation

FileBuffer(
  this.file, {
  this.byteOrder = ByteOrder.littleEndian,
  int bufferSize = kDefaultBufferSize,
}) {
  if (!file.isOpen) {
    file.open();
  }
  _fileSize = file.length;
  // Prevent having a buffer smaller than the minimum buffer size
  _bufferSize = max(
    // If possible, avoid having a buffer bigger than the file itself
    min(bufferSize, _fileSize),
    kMinBufferSize,
  );
  _buffer = Uint8List(_bufferSize);
  _readBuffer(0, _fileSize);
}