go-cloud icon indicating copy to clipboard operation
go-cloud copied to clipboard

blob: add io/fs.FS support

Open VoyTechnology opened this issue 4 years ago • 0 comments

Having a common interface for reading and writing blob data across all cloud providers is very useful, however with the addition of the io/fs package in Go 1.16 means that we can integrate even more into the standard library.

Possible Solution

A couple of changes would have to be added to comply with the fs.FS implementation


type Bucket struct {
  // used for (*Bucket.Open)
  ctx context.Context
  
  // ...
}

func applyPrefixParam(ctx context.Context, opener BucketURLOpener, u *url.URL) ) (*Bucket, error) {
  // ...
  // Add the context before returning. This doesn't seem like the most elegant way but I
  // I can't think of an alternative, so would have to be improved. This is only used for
  // (*Bucket).Open
  b.ctx = ctx
  return bucket, nil
}

func (*Bucket) Open(name string) (fs.File, error) {
  // See above of how we would pass in the context.
  // How the *ReaderOptions can be passed in is a bit harder.
  return b.NewReader(b.ctx, name, nil)
}

func (*Reader) Stat() (fs.FileInfo, error) {
  // FileInfo implementation is completely missing as is, and would have to be added.
}

// (*Reader).Read and (*Reader).Close is already implemented.

The biggest change would have to be the addition of the fs.FileInfo to the (*Reader).Stat, as well as passing in the context and *ReaderOptions.

Alternatives and References

Additional context

At the moment the fs.FS interface is Read-only, it means that for writing files there is nothing that can be done.

VoyTechnology avatar Oct 12 '21 20:10 VoyTechnology