-
Notifications
You must be signed in to change notification settings - Fork 0
/
gocloud.go
46 lines (34 loc) · 947 Bytes
/
gocloud.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
package bucket
import (
"context"
"fmt"
"io"
"github.com/protomaps/go-pmtiles/pmtiles"
"gocloud.dev/blob"
)
type GoCloudBucket struct {
pmtiles.Bucket
bucket *blob.Bucket
}
func NewGoCloudBucket(ctx context.Context, uri string, prefix string) (*GoCloudBucket, error) {
b, err := blob.OpenBucket(ctx, uri)
if err != nil {
return nil, fmt.Errorf("Failed to open bucket, %w", err)
}
if prefix != "" {
b = blob.PrefixedBucket(b, prefix)
}
gcb := &GoCloudBucket{
bucket: b,
}
return gcb, nil
}
func (gcb *GoCloudBucket) Close() error {
return gcb.bucket.Close()
}
func (gcb *GoCloudBucket) NewRangeReader(ctx context.Context, key string, offset, length int64) (io.ReadCloser, error) {
return gcb.bucket.NewRangeReader(ctx, key, offset, length, nil)
}
func (gcb *GoCloudBucket) NewWriter(ctx context.Context, key string, opts *blob.WriterOptions) (*blob.Writer, error) {
return gcb.bucket.NewWriter(ctx, key, opts)
}