package examples

import "github.com/ipfs/go-datastore/examples"

Package fs is a simple Datastore implementation that stores keys as directories and files, mirroring the key. That is, the key "/foo/bar" is stored as file "PATH/foo/bar/.dsobject".

This means key some segments will not work. For example, the following keys will result in unwanted behavior:

Keys that only differ in case may be confused with each other on case insensitive file systems, for example in OS X.

This package is intended for exploratory use, where the user would examine the file system manually, and should only be used with human-friendly, trusted keys. You have been warned.

Index

Variables

var ObjectKeySuffix = ".dsobject"

Functions

func NewDatastore

func NewDatastore(path string) (ds.Datastore, error)

NewDatastore returns a new fs Datastore at given `path`

Types

type Datastore

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

Datastore uses a uses a file per key to store values.

func (*Datastore) Batch

func (d *Datastore) Batch(ctx context.Context) (ds.Batch, error)

func (*Datastore) Close

func (d *Datastore) Close() error

func (*Datastore) Delete

func (d *Datastore) Delete(ctx context.Context, key ds.Key) (err error)

Delete removes the value for given key

func (*Datastore) DiskUsage

func (d *Datastore) DiskUsage(ctx context.Context) (uint64, error)

DiskUsage returns the disk size used by the datastore in bytes.

func (*Datastore) Get

func (d *Datastore) Get(ctx context.Context, key ds.Key) (value []byte, err error)

Get returns the value for given key

func (*Datastore) GetSize

func (d *Datastore) GetSize(ctx context.Context, key ds.Key) (size int, err error)

func (*Datastore) Has

func (d *Datastore) Has(ctx context.Context, key ds.Key) (exists bool, err error)

Has returns whether the datastore has a value for a given key

func (*Datastore) KeyFilename

func (d *Datastore) KeyFilename(key ds.Key) string

KeyFilename returns the filename associated with `key`

func (*Datastore) Put

func (d *Datastore) Put(ctx context.Context, key ds.Key, value []byte) (err error)

Put stores the given value.

func (*Datastore) Query

func (d *Datastore) Query(ctx context.Context, q query.Query) (query.Results, error)

Query implements Datastore.Query

func (*Datastore) Sync

func (d *Datastore) Sync(ctx context.Context, prefix ds.Key) error

Sync would ensure that any previous Puts under the prefix are written to disk. However, they already are.

Source Files

fs.go

Version
v0.8.2 (latest)
Published
Mar 4, 2025
Platform
linux/amd64
Imports
8 packages
Last checked
1 month ago

Tools for package owners.