readByteDataCopy method

ByteData readByteDataCopy(
  1. int length
)

Returns the next length bytes. The method always returns a new copy of the bytes.

Increments index by length.

Implementation

ByteData readByteDataCopy(int length) {
  final byteData = this._byteData;
  final result = new ByteData(length);
  var i = 0;

  // If 128 or more bytes, we read in 4-byte chunks.
  // This should be faster.
  //
  // This constant is just a guess of a good minimum.
  if (length >> 7 != 0) {
    final optimizedDestination = new Uint32List.view(
        result.buffer, result.offsetInBytes, result.lengthInBytes);
    while (i + 3 < length) {
      // Copy in 4-byte chunks.
      // We must use host endian during reading.
      optimizedDestination[i] = byteData.getUint32(index + i, Endian.host);
      i += 4;
    }
  }
  for (; i < result.lengthInBytes; i++) {
    result.setUint8(i, byteData.getUint8(index + i));
  }
  this.index = index + length;
  return result;
}