diff options
| author | Marin Ivanov <[email protected]> | 2022-08-15 00:15:04 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2022-08-15 00:15:04 +0300 |
| commit | b135dcf644394394e3250188dea39ff4e91f0e06 (patch) | |
| tree | fa5946e5ee66c39fde185dc145274c4e85d36d51 /fs.go | |
| parent | de77a507ecfe16a9538b20c66ca075a7f780428b (diff) | |
Add Fs.Open() and read file test
Diffstat (limited to 'fs.go')
| -rw-r--r-- | fs.go | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "io" neturl "net/url" "os" "strings" @@ -91,8 +92,13 @@ func (fs *Fs) MkdirAll(path string, perm os.FileMode) error { } // Open opens a file, returning it or an error, if any happens. -func (fs *Fs) Open(name string) (File, error) { - panic("not implemented") +func (fs *Fs) Open(name string) (afero.File, error) { + ctx, cancel := fs.contextWithTimeout() + obj, err := fs.client.GetObject(ctx, fs.bucket, name, minio.GetObjectOptions{}) + if err != nil { + return nil, err + } + return fs.newObjectReader(name, obj, cancel), nil } // OpenFile opens a file using the given flags and the given mode. @@ -181,6 +187,15 @@ func (fs *Fs) contextWithTimeout() (context.Context, context.CancelFunc) { return context.WithTimeout(context.Background(), fs.Timeout) } +func (fs *Fs) newObjectReader(key string, r io.ReadCloser, cancel context.CancelFunc) *File { + return &File{ + fs: fs, + key: key, + r: r, + cancel: cancel, + } +} + func transformError(err error) error { resp, ok := err.(minio.ErrorResponse) if !ok { |
