subset method

  1. @override
Uint8List subset(
  1. int start, [
  2. int? end
])
override

Implementation

@override
Uint8List subset(int start, [int? end]) {
  final pos = _fileHandle.position + _bufferPosition;

  if (start < 0) {
    start = pos + start;
  }
  if (end != null && end < 0) {
    end = pos + end;
  }

  if (_bufferPosition > 0) {
    if (start >= _fileHandle.position) {
      if (end == null) {
        end = _fileHandle.position + _bufferPosition;
      }
      final length = end - start;
      final bufferStart = start - _fileHandle.position;
      final bufferEnd = bufferStart + length;
      final bytes = _buffer.sublist(bufferStart, bufferEnd);
      return bytes;
    }
    flush();
  }

  var length = 0;
  if (end == null) {
    end = pos;
  } else if (end < 0) {
    end = pos + end;
  }
  length = end - start;
  _fileHandle.position = start;
  final buffer = Uint8List(length);
  _fileHandle.readInto(buffer);
  _fileHandle.position = pos;
  return buffer;
}