Bytes.fromTypedData constructor

Bytes.fromTypedData(
  1. TypedData data
)

Zero-copy view over any Dart TypedData.

Covers Uint8List, ByteData, Int32List, etc. The view shares the underlying ByteBuffer; later mutation of the backing storage is visible through this Bytes.

Implementation

factory Bytes.fromTypedData(TypedData data) {
  final view = Uint8List.view(
    data.buffer,
    data.offsetInBytes,
    data.lengthInBytes,
  );
  return Bytes._(view, 0, view.length);
}