bytesInRange method

  1. @override
Uint8List bytesInRange(
  1. int startByte,
  2. int endByte
)
override

Implementation

@override
Uint8List bytesInRange(int startByte, int endByte) {
  RangeError.checkValidRange(startByte, endByte, _byteLength);
  final result = Uint8List(endByte - startByte);
  var output = 0;
  var position = 0;
  for (final piece in _pieces) {
    final pieceEnd = position + piece.length;
    if (pieceEnd <= startByte) {
      position = pieceEnd;
      continue;
    }
    if (position >= endByte) break;
    final localStart = startByte > position ? startByte - position : 0;
    final localEnd = endByte < pieceEnd ? endByte - position : piece.length;
    result.setRange(
      output,
      output + localEnd - localStart,
      piece,
      localStart,
    );
    output += localEnd - localStart;
    position = pieceEnd;
  }
  return result;
}