read method

Future<ByteData?> read({
  1. IntRange? range,
})

Reads all the bytes or the given range.

It can be used to check a file signature, aka magic number. See https://en.wikipedia.org/wiki/List_of_file_signatures

Implementation

Future<ByteData?> read({IntRange? range}) =>
    waitTryOrNull(() async => stream().letAsync((stream) async =>
        RawDataStream((await stream?.first) ?? [])
            .readData(start: range?.start, length: range?.length)
            .then((data) => data.toByteData())));