giostorage

package module
v0.0.0-...-1b4a24f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 8 Imported by: 0

README

giostorage

That package was created to cache some information, because nobody likes to wait for a http response. This package was designed to save small data, like user preferences, profile pictures and related names.

Due to privacy reasons, giostorage also provides an encrypted implementation. That is useful to keep way others users (or others unprivileged apps) from reading the content.

It's currently being used on WebAssembly, Windows and Android. It may work on Linux, Darwin and iOS, but it's not tested.


Known-Bug: You can't open files on Android before the gio initialize. So, you can't open any file on func init(){}, for instance. The best idea is to open files on the first system.StageEvent.


Why not use os.Open?

Because you can't, in some OSes. It's not supported on WebAssembly. If WASM isn't a concern, you can use os.Open, just fine. (:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EncryptedKeySize = chacha20.KeySize
)

Functions

This section is empty.

Types

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage provides the Open and Create functions, using an arbitrary storage implementation. You should create the Storage from NewPlainStorage or NewEncryptedStorage.

func NewEncryptedStorage

func NewEncryptedStorage(name string, key []byte) (*Storage, error)

NewEncryptedStorage creates a Storage encrypted by unauthenticated ChaCha20X. The key must be chacha20.KeySize. The salt is created at random, using rand.Read.

The file can be modified without any sign of change, similarly as plain-text files. Beware that the key is already on the client's computer, so it's possible to re-encrypt an arbitrary data.

func NewPlainStorage

func NewPlainStorage(name string) *Storage

NewPlainStorage creates a Storage.

func (*Storage) Create

func (s *Storage) Create(name string) (io.WriteCloser, error)

Create creates (or truncate, if exists) the file.

func (*Storage) Open

func (s *Storage) Open(name string) (io.ReadCloser, error)

Open opens the file.

func (*Storage) ReadInterface

func (s *Storage) ReadInterface(name string, resp interface{}) error

ReadInterface will read the given resp interface, from the file. It uses gob.

func (*Storage) WriteInterface

func (s *Storage) WriteInterface(name string, data interface{}) error

WriteInterface will write given data interface into a file. It uses gob.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL