-
Notifications
You must be signed in to change notification settings - Fork 3
/
example_test.go
60 lines (50 loc) · 1015 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package bfs_test
import (
"context"
"fmt"
"io"
"github.com/bsm/bfs"
)
func ExampleInMem() {
ctx := context.Background()
bucket := bfs.NewInMem()
// Write object
o1, err := bucket.Create(ctx, "nested/file.txt", nil)
if err != nil {
panic(err)
}
defer o1.Discard()
if _, err := o1.Write([]byte("TESTDATA")); err != nil {
panic(err)
}
if err := o1.Commit(); 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 := io.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)
}
}