Skip to content

Latest commit

 

History

History
90 lines (57 loc) · 2.37 KB

README.md

File metadata and controls

90 lines (57 loc) · 2.37 KB

local-fs

Local File System Database

Health Check

godoc for jancajthaml-openbank/local-fs

codebeat badge

Usage

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")

Encryption of data at rest

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")

License

Licensed under Apache 2.0 see LICENSE.md for details

FOSSA Status