copy method

void copy(
  1. Buffer dst, [
  2. int dstOffset = 0,
  3. int offset = 0,
  4. int? length,
])

Copies items from this buffer to the destination (dst) buffer.

Items are copied to dst starting at position dstOffset.

Items are copied from the range [offset : offset+length]. If length is omitted, the range extends to the end of this or [dst] (whichever has the minimum length).

The range must satisy the relations 0offsetoffset+lengththis.length.

final Buffer src = Buffer.fromList([1, 2, 3, 4, 5, 6, 7, 8]);
final Buffer dst = Buffer(4);
src.copy(dst, 0, 2);
print(src); // [1, 2, 3, 4, 5, 6, 7, 8]
print(dst); // [3, 4, 5, 6]

Implementation

void copy(
  final Buffer dst, [
  final int dstOffset = 0,
  final int offset = 0,
  final int? length,
]) {
  final int rngLength =
      length ?? min(dst.length - dstOffset, this.length - offset);
  final Iterable<int> src = _data.getRange(offset, offset + rngLength);
  dst._data.setRange(dstOffset, dstOffset + rngLength, src);
}