Skip to content

Detects if a `.db` file was created with LiteDB 4 or LiteDB 5 using binary header analysis.

Notifications You must be signed in to change notification settings

zalza13/LiteDb.VersionChecker

Repository files navigation

LiteDb.VersionChecker

πŸ” Simple and reliable utility to detect if a .db file was created with LiteDB 4 or LiteDB 5 β€” without trying to open the file.

🧠 Based on the actual internal logic used by LiteDB to determine file structure versions (FileReaderV7, FileReaderV8, etc.).

✨ Features

  • βœ… Detects LiteDB 4 files (datafile version 7)
  • βœ… Detects LiteDB 5 files (datafile version 8)
  • βœ… Works even on encrypted LiteDB 5 files
  • βœ… Zero dependencies
  • βœ… .NET Standard 2.0+ / .NET 6+ compatible

πŸš€ Installation

If published as a NuGet package:

dotnet add package LiteDb.VersionChecker

Otherwise, just copy the class from LiteDbVersionDetector.cs into your project.

πŸ§ͺ Usage

string version = LiteDbVersionDetector.DetectLiteDbVersion("mydata.db");
Console.WriteLine($"Detected version: {version}");

Output:

LiteDB 4
LiteDB 5
No LiteDB file

πŸ” How it works

LiteDB stores internal metadata at fixed offsets inside the first 1024 bytes of the file.

This library reads:

  • A special header string: ** This is a LiteDB file **
  • A version byte:
    • 7 β†’ LiteDB 4
    • 8 β†’ LiteDB 5
  • Encrypted LiteDB 5 files are detected by checking buffer[0] == 1

πŸ“‚ File structure detection

Version Offset Value
Header 25 (v4) / 32 (v5) ** This is a LiteDB file **
Version 52 (v4) / 59 (v5) 7 or 8
Encrypted 0 1 if file is encrypted (v5+)

πŸ“œ License

MIT β€” Free for personal and commercial use.


Contributions welcome! If LiteDB won't merge it, let's improve it together here πŸ˜‰

About

Detects if a `.db` file was created with LiteDB 4 or LiteDB 5 using binary header analysis.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages