summaryrefslogtreecommitdiff
path: root/fs.go
diff options
context:
space:
mode:
Diffstat (limited to 'fs.go')
-rw-r--r--fs.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/fs.go b/fs.go
index a4a1831..2b2e876 100644
--- a/fs.go
+++ b/fs.go
@@ -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 {