readHeader static method

Future<(String, int, String)> readHeader(
  1. String dbPath, {
  2. String? requiredType,
  3. int? requiredVersion,
})

Read Header

Return (magic,version,type)

Implementation

static Future<(String, int, String)> readHeader(
  String dbPath, {
  String? requiredType,
  int? requiredVersion,
}) async {
  final file = File(dbPath);
  if (!file.existsSync()) {
    throw Exception('DB File Not Found!');
  }
  final raf = await file.open(mode: FileMode.read);

  final (magic, version, type) = await BinaryRW.readHeader(raf);
  if (requiredType != null) {
    if (type != requiredType) {
      throw Exception(
        'Invalid DB Database `Type`: Excepted `$requiredType` Got `$type`',
      );
    }
  }
  if (requiredVersion != null) {
    if (version != requiredVersion) {
      throw Exception(
        'Invalid DB Database `Version`: Excepted `$requiredVersion` Got `$version`',
      );
    }
  }
  return (type, version, type);
}