indexOf method

  1. @override
int indexOf(
  1. int byte, [
  2. int offset = 0,
  3. int? length
])
override

Returns the index of byte inf offset and length range.

Implementation

@override
int indexOf(int byte, [int offset = 0, int? length]) {
  if (offset >= _length) return -1;

  length ??= _length - offset;

  var end = offset + length;
  if (end > _length) {
    end = _length;
  }

  final bsSz = math.min(1024 * 4, _length - offset);
  final bs = Uint8List(bsSz);

  _ioSetPosition(offset);

  for (var p = offset; p < end;) {
    var lng = end - p;
    if (lng > bsSz) lng = bsSz;

    _ioReadBytes(bs, 0, lng);

    var idx = bs.indexOf(byte);
    if (idx >= 0 && idx < lng) {
      var idxPos = p + idx;
      return idxPos;
    }

    p += lng;
  }

  return -1;
}