writeFromSync method
Implementation
int writeFromSync(List<int> buffer, [int start = 0, int? end]) {
if (_readOnly) {
throw Exception('Cannot write to read-only RAM file data');
}
final int usedStart = start;
final int usedEnd = end ?? (start + buffer.length);
int bufferStartWriteIndex = 0;
int relativeStart;
do {
relativeStart = usedStart + bufferStartWriteIndex;
final int contentIndex = relativeStart ~/ _subListSize;
while (contentIndex >= _content.length) {
_content.add(Uint8List(_subListSize));
}
final List<int> contentSubList = _content[contentIndex];
final int subListStartIndex = relativeStart % _subListSize;
final int dataLengthToCopy = math.min(
usedEnd - relativeStart,
_subListSize - subListStartIndex,
);
contentSubList.setRange(
subListStartIndex,
subListStartIndex + dataLengthToCopy,
buffer.getRange(
bufferStartWriteIndex,
bufferStartWriteIndex + dataLengthToCopy,
),
);
bufferStartWriteIndex += dataLengthToCopy;
} while (relativeStart < usedEnd);
_length = math.max(usedEnd, _length);
return usedEnd - start;
}