slice method
Creates a new Buffer from a region of this
buffer.
Items are copied from the range [offset : offset+length]
. If length
is omitted, the range
extends to the end of the buffer.
The range must satisy the relations 0
≤ offset
≤ offset+length
≤ this.length
.
final Buffer buffer = Buffer.fromList([1, 2, 3, 4, 5, 6, 7, 8]);
final Buffer newBuffer = buffer.slice(4);
print(buffer); // [1, 2, 3, 4, 5, 6, 7, 8]
print(newBuffer); // [5, 6, 7, 8]
Implementation
Buffer slice([final int offset = 0, final int? length]) {
final int? end = length != null ? offset + length : null;
return Buffer.fromList(_data.sublist(offset, end));
}