Collection of key-value storages adapters for Golang
This project is maintained by reddec
github.com/reddec/storages/std/filestorage
Constructors: New
, NewDefault
Puts each data to separate file. File name generates from hash function (by default SHA256) applied to key. To prevent generates too much files in one directory, each filename is chopped to 4 slices by 4 characters.
Do not forget to import package!
file://<path>
Where:
<path>
- path to root directoryConstructor: NewFlat
Key is equal to file name. Sub-directories (/
in key name) are not allowed.
Namespace are share key space with regular values.
Do not forget to import package!
file+flat://<path>
Where:
<path>
- path to root directoryConstructor: NewJSONFile
Stores everything in one file. File overwrites atomically.
With JSON encoding all data presented as dictionary in data
field and namespaces in namespaces
field.
All information cached in-memory. Any modification operation will rewrite file fully.
This kind of storage is limited by RAM size and requires quite a number of sycalls for update. So it’s good for:
Do not forget to import package!
file+json://<path>
Where:
<path>
- path to fileFlat
stor := filestorage.NewFlat("path/to/directory")
// Close() not required but implemented as NOP
Encoded
stor := filestorage.NewDefault("path/to/directory")
// Close() not required but implemented as NOP
Support NamespacedStorage interface.
It allows make nested sub-storages with independent key space.
Example:
aliceStorage := storage.Namespace([]byte("alice"))
bobStorage := storage.Namespace([]byte("bob"))