Local File System Database
both plaintext and encrypted storage have same api
import (
localfs "github.com/jancajthaml-openbank/local-fs"
)
...
storage := localfs.NewPlaintextStorage("/tmp")
// list nodes at /tmp/foo in ascending order
asc, err := storage.ListDirectory("foo", true)
// list nodes at /tmp/foo in descending order
desc, err := storage.ListDirectory("foo", false)
// count files at /tmp/foo
count, err := storage.CountFiles("foo")
// check if /tmp/foo exists
ok, err := storage.Exists("foo")
// delete file /tmp/foo
err := storage.Delete("foo")
// creates file /tmp/foo if not exists
err := storage.TouchFile("foo")
// ovewrites file /tmp/foo with "abc", creates file if it does not exist
err := storage.WriteFile("foo", []byte("abc"))
// crates and writes file /tmp/foo with "abc", fails if file exists
err := storage.WriteFileExclusive("foo", []byte("abc"))
// appends "abc" to end of /tmp/foo file, fails if file does not exist
err := storage.AppendFile("foo", []byte("abc"))
// read all bytes of file /tmp/foo
data, err := storage.ReadFileFully("tmp")
// read all bytes of file /tmp/foo
data, err := storage.ReadFileFully("tmp")
// returns reader for /tmp/foo
fd, err := storage.GetFileReader("tmp")
Generate some key
openssl rand -hex 32 | xargs --no-run-if-empty echo -n > /tmp/secrets/key
Write and read encrypted data at /tmp/data/foo
import (
localfs "github.com/jancajthaml-openbank/local-fs"
)
...
storage := localfs.NewEncryptedStorage("/tmp/data", "/tmp/secrets/key")
err := storage.WriteFile("foo", []byte("pii"))
...
data, err := storage.ReadFileFully("/tmp/data/foo")
Licensed under Apache 2.0 see LICENSE.md for details