RawReader.withBytes constructor
RawReader.withBytes(
- List<int> bytes, {
- bool isCopyOnRead = true,
})
Implementation
factory RawReader.withBytes(List<int> bytes, {bool isCopyOnRead = true}) {
ByteData byteData;
if (bytes is Uint8List) {
// Use existing buffer
byteData = new ByteData.view(
bytes.buffer,
bytes.offsetInBytes,
bytes.lengthInBytes,
);
} else {
// Allocate a new buffer
byteData = new ByteData(bytes.length);
// Copy bytes to the new buffer
final writer = new RawWriter.withByteData(byteData, isExpanding: false);
writer.writeBytes(bytes);
}
return new RawReader.withByteData(
byteData,
isCopyOnRead: isCopyOnRead,
);
}