take method
Returns a view of the leading count bytes and releases them from this
accumulator. The returned list keeps the previous backing store alive.
Implementation
Uint8List take(int count) {
_checkRange(count);
final old = _data;
if (count == _length) {
_data = Uint8List(_defaultInitialCapacity);
_length = 0;
if (count == old.length) {
return old;
}
return Uint8List.sublistView(old, 0, count);
}
final remaining = _length - count;
final nextCapacity = remaining < _defaultInitialCapacity
? _defaultInitialCapacity
: remaining;
final next = Uint8List(nextCapacity)..setRange(0, remaining, old, count);
_data = next;
_length = remaining;
return Uint8List.sublistView(old, 0, count);
}