An open API service indexing awesome lists of open source software.

https://github.com/zalza13/litedb.versionchecker

Detects if a `.db` file was created with LiteDB 4 or LiteDB 5 using binary header analysis.
https://github.com/zalza13/litedb.versionchecker

database-tools dotnet file-inspector litedb litedb-database version-checker

Last synced: 4 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# 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:

```bash
dotnet add package LiteDb.VersionChecker
```

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

## ๐Ÿงช Usage

```csharp
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 ๐Ÿ˜‰