isValidDatabaseFile static method
Implementation
static Future<bool> isValidDatabaseFile(String filePath) async {
final file = File(filePath);
if (!(await file.exists())) {
return false; // File does not exist
}
final headerBytes = await file.openRead(0, 16).first;
// SQLite database file header
const List<int> sqliteHeader = [
0x53,
0x51,
0x4c,
0x69,
0x74,
0x65,
0x20,
0x66,
0x6f,
0x72,
0x6d,
0x61,
0x74,
0x20,
0x33,
0x00
];
return headerBytes.length == sqliteHeader.length &&
headerBytes
.every((byte) => byte == sqliteHeader[headerBytes.indexOf(byte)]);
}