sniffFileSync function

AudioProbe sniffFileSync(
  1. String path
)

Synchronous sniffFile.

Prefer this inside Flutter widget tests: they run on a fake clock, and asynchronous file I/O may never complete there.

Implementation

AudioProbe sniffFileSync(String path) {
  final file = File(path).openSync();
  try {
    final length = file.lengthSync();
    return probeWith(
      ByteReader((offset, count) {
        try {
          file.setPositionSync(offset);
          return file.readSync(count);
        } on FileSystemException {
          return Uint8List(0);
        }
      }, length),
    );
  } finally {
    file.closeSync();
  }
}