isStreamingFile static method

Future<bool> isStreamingFile(
  1. File file
)

Returns true if file begins with the streaming-envelope magic, so a reader can auto-route between .pqfs and one-shot envelopes.

Implementation

static Future<bool> isStreamingFile(File file) async {
  final magic = PqBytes.utf8Bytes(PqStreamingEnvelope.magic);
  final raf = await file.open();
  try {
    final head = Uint8List(magic.length);
    final read = await raf.readInto(head);
    if (read < magic.length) return false;
    for (var i = 0; i < magic.length; i++) {
      if (head[i] != magic[i]) return false;
    }
    return true;
  } finally {
    await raf.close();
  }
}