validate_sqlite_file

Function validate_sqlite_file 

Source
pub fn validate_sqlite_file(data: &[u8]) -> Result<(), DatabaseError>
Expand description

Validate SQLite database file format

Performs comprehensive validation of a SQLite database file to ensure it can be safely imported. Checks file structure, magic string, page size validity, and size consistency.

§Arguments

  • data - Complete SQLite database file as bytes

§Returns

  • Ok(()) - File is valid and safe to import
  • Err(DatabaseError) - File is invalid with detailed error message

§Validation Checks

  • File size is at least 100 bytes (minimum header size)
  • Magic string matches “SQLite format 3\0”
  • Page size is valid (power of 2, between 512 and 65536)
  • Page count is non-zero
  • File size matches (page_size × page_count)

§Example

use absurder_sql::storage::export::validate_sqlite_file;

let file_data = std::fs::read("database.db").unwrap();
match validate_sqlite_file(&file_data) {
    Ok(()) => println!("Valid SQLite file"),
    Err(e) => eprintln!("Invalid file: {}", e),
}