putBytes method

void putBytes(
  1. List<int> bytes, {
  2. int start = 0,
  3. int length = -1,
})

This method transfers bytes into this writer from the given source array.

@param bytes The array from which bytes are to be read @param start The offset within the array of the first byte to be read @param length The number of bytes to be read from the given array

Implementation

void putBytes(List<int> bytes, {int start = 0, int length = -1}) {
  if (length == 0) {
    return;
  }

  var insertFullLength = bytes.length - start;
  if (insertFullLength < 0) {
    throw ArgumentError(
        "illegal write bytes, put start pos($start) out of bytes length(${bytes.length})");
  }

  var realLength = insertFullLength;
  if (length > 0) {
    realLength = min(insertFullLength, length);
  }

  if (realLength <= 0) {
    return;
  }
  for (var i = 0; i < realLength; i++) {
    putByte(bytes[i + start]);
  }
}