Skip to content

Commit 044c2c1

Browse files
committed
blob/all: Don't require SetIOFSCallback to use io/fs.FS functions
1 parent d2adbc5 commit 044c2c1

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

blob/blob.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ var NewBucket = newBucket
694694
func newBucket(b driver.Bucket) *Bucket {
695695
return &Bucket{
696696
b: b,
697+
ioFSCallback: func() (context.Context, *ReaderOptions) { return context.Background(), nil },
697698
tracer: &oc.Tracer{
698699
Package: pkgName,
699700
Provider: oc.ProviderName(b),

blob/blob_fs.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,15 @@ func (d *iofsDir) openOnce() error {
158158
//
159159
// fn should return a context.Context and *ReaderOptions that can be used in
160160
// calls to List and NewReader on b. It may be called more than once.
161+
//
162+
// If SetIOFSCallback is never called, io.FS functions will use context.Background
163+
// and a default ReaderOptions.
161164
func (b *Bucket) SetIOFSCallback(fn func() (context.Context, *ReaderOptions)) {
162165
b.ioFSCallback = fn
163166
}
164167

165168
// Open implements fs.FS.Open (https://pkg.go.dev/io/fs#FS).
166-
//
167-
// SetIOFSCallback must be called prior to calling this function.
168169
func (b *Bucket) Open(path string) (fs.File, error) {
169-
if b.ioFSCallback == nil {
170-
return nil, gcerr.Newf(gcerr.InvalidArgument, nil, "blob: Open -- SetIOFSCallback must be called before Open")
171-
}
172170
if !fs.ValidPath(path) {
173171
return nil, &fs.PathError{Op: "open", Path: path, Err: fs.ErrInvalid}
174172
}

blob/blob_fs_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func initBucket(t *testing.T, files []string) *blob.Bucket {
4242
ctx := context.Background()
4343

4444
b := memblob.OpenBucket(nil)
45-
b.SetIOFSCallback(func() (context.Context, *blob.ReaderOptions) { return ctx, nil })
4645
for _, f := range files {
4746
if err := b.WriteAll(ctx, f, []byte("data"), nil); err != nil {
4847
t.Fatal(err)

0 commit comments

Comments
 (0)