From b5043e1319d4c1cac99975825bc6f483508fb1b9 Mon Sep 17 00:00:00 2001 From: nxshock Date: Fri, 2 Dec 2022 21:37:56 +0500 Subject: [PATCH] Add README with small amount of documentation --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f250cd2 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# zkv + +Simple key-value store for single-user applications. + +## Pros + +* Simple file structure +* Internal compression +* Threadsafe operations through `sync.RWMutex` + +## Cons + +* Index stored in memory (`map[key hash (28 bytes)]file offset (int64)`) +* Need to read the whole file on store open to create file index +* No way to recover disk space from deleted records +* Write/Delete operations block Read and each other operations + +## Usage + +Create or open existing file: + +```go +db, err := Open("path to file") +``` + +Data operations: + +```go +// Write data +err = db.Set(key, value) // key and value can be any of type + +// Read data +var value ValueType +err = db.Get(key) + +// Delete data +err = db.Delete(key) +``` + +## File structure + +Record is `encoding/gob` structure: + +| Field | Description | Size | +| ---------- | ---------------------------------- | -------- | +| Type | Record type | uint8 | +| KeyHash | Key hash | 28 bytes | +| ValueBytes | Value gob-encoded bytes | variable | + +File is log stuctured list of commands: + +| Field | Description | Size | +| -------| ------------------------ | -------- | +| Length | Record body bytes length | int64 | +| Body | Gob-encoded record | variable |