From 86ac21b3e5c2acc29ed40b97ea5c1ab5d2b521f1 Mon Sep 17 00:00:00 2001 From: wangyelei Date: Tue, 7 Nov 2023 11:21:25 +0800 Subject: [PATCH] chore: storage interface support ReadObject function --- pkg/storage/rclone/rclone.go | 9 +++++++++ pkg/storage/types.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/pkg/storage/rclone/rclone.go b/pkg/storage/rclone/rclone.go index a0ff6ba..0b1e21b 100644 --- a/pkg/storage/rclone/rclone.go +++ b/pkg/storage/rclone/rclone.go @@ -84,6 +84,15 @@ func (s *rcloneStorage) Pull(ctx context.Context, rpath string, w io.Writer) err return err } +func (s *rcloneStorage) ReadObject(ctx context.Context, rpath string) (io.ReadCloser, error) { + rpath = normalizeRemotePath(rpath) + obj, err := s.f.NewObject(ctx, rpath) + if err != nil { + return nil, err + } + return obj.Open(ctx) +} + func (s *rcloneStorage) Remove(ctx context.Context, rpath string, recursive bool) error { rpath = normalizeRemotePath(rpath) if !recursive { diff --git a/pkg/storage/types.go b/pkg/storage/types.go index a701752..e7e6634 100644 --- a/pkg/storage/types.go +++ b/pkg/storage/types.go @@ -56,6 +56,9 @@ type Storage interface { // Stat returns the information about the given path. // The `rpath` parameter can be a file. Stat(ctx context.Context, rpath string) (StatResult, error) + + // ReadObject reads a file. + ReadObject(ctx context.Context, rpath string) (io.ReadCloser, error) } type staticDirEntry struct {