Documentation
¶
Overview ¶
Package bfs outlines an abstraction for bucket-based fyle systems with mock-implmentations.
Index ¶
- Variables
- func CopyObject(bucket Bucket, ctx context.Context, src, dst string) error
- func WriteObject(bucket Bucket, ctx context.Context, name string, data []byte) error
- type Bucket
- type InMem
- func (*InMem) Close() error
- func (b *InMem) Create(_ context.Context, name string) (io.WriteCloser, error)
- func (b *InMem) Glob(_ context.Context, pattern string) ([]string, error)
- func (b *InMem) Head(_ context.Context, name string) (*MetaInfo, error)
- func (b *InMem) Open(_ context.Context, name string) (io.ReadCloser, error)
- func (b *InMem) Remove(_ context.Context, name string) error
- type MetaInfo
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotFound = errors.New("bfs: object not found")
ErrNotFound must be returned by all implementations when a requested object cannot be found.
Functions ¶
func CopyObject ¶
CopyObject is a quick copy helper.
Types ¶
type Bucket ¶
type Bucket interface {
// Glob lists the files mathing a glob pattern.
Glob(ctx context.Context, pattern string) ([]string, error)
// Head returns an object's meta Info.
Head(ctx context.Context, name string) (*MetaInfo, error)
// Open opens an object for reading.
Open(ctx context.Context, name string) (io.ReadCloser, error)
// Create creates/opens a object for writing.
Create(ctx context.Context, name string) (io.WriteCloser, error)
// Remove removes a object.
Remove(ctx context.Context, name string) error
// Close closes the bucket.
Close() error
}
Bucket is an abstract storage bucket.
type InMem ¶
type InMem struct {
// contains filtered or unexported fields
}
InMem is an in-memory Bucket implementation which can be used for mocking.
Example ¶
package main
import (
"context"
"fmt"
"io/ioutil"
"github.com/bsm/bfs"
)
func main() {
ctx := context.Background()
bucket := bfs.NewInMem()
// Write object
o1, err := bucket.Create(ctx, "nested/file.txt")
if err != nil {
panic(err)
}
defer o1.Close()
if _, err := o1.Write([]byte("TESTDATA")); err != nil {
panic(err)
}
if err := o1.Close(); err != nil {
panic(err)
}
// Glob entries
entries, err := bucket.Glob(ctx, "nested/*")
if err != nil {
panic(err)
}
fmt.Println("ENTRIES:", entries)
// Read object
o2, err := bucket.Open(ctx, "nested/file.txt")
if err != nil {
panic(err)
}
defer o2.Close()
data, err := ioutil.ReadAll(o2)
if err != nil {
panic(err)
}
fmt.Println("DATA:", string(data))
// Head object
info, err := bucket.Head(ctx, "nested/file.txt")
if err != nil {
panic(err)
}
fmt.Printf("INFO: name=%q size=%d\n", info.Name, info.Size)
// Delete object
if err := bucket.Remove(ctx, "nested/file.txt"); err != nil {
panic(err)
}
}
Output:
Click to show internal directories.
Click to hide internal directories.