Skip to content

Commit

Permalink
refactor: PutObject only needs io.Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Jun 12, 2024
1 parent 7b5398c commit 4f5e944
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion storage/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *StorageFS) GetObject(bucket Bucket, fpath string) (utils.ReaderAtCloser
return dat, info.Size(), info.ModTime(), nil
}

func (s *StorageFS) PutObject(bucket Bucket, fpath string, contents utils.ReaderAtCloser, entry *utils.FileEntry) (string, error) {
func (s *StorageFS) PutObject(bucket Bucket, fpath string, contents io.Reader, entry *utils.FileEntry) (string, error) {
loc := filepath.Join(bucket.Path, fpath)
err := os.MkdirAll(filepath.Dir(loc), os.ModePerm)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion storage/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"io"
"net/url"
"os"
"strconv"
Expand Down Expand Up @@ -176,7 +177,7 @@ func (s *StorageMinio) GetObject(bucket Bucket, fpath string) (utils.ReaderAtClo
return obj, info.Size, modTime, nil
}

func (s *StorageMinio) PutObject(bucket Bucket, fpath string, contents utils.ReaderAtCloser, entry *utils.FileEntry) (string, error) {
func (s *StorageMinio) PutObject(bucket Bucket, fpath string, contents io.Reader, entry *utils.FileEntry) (string, error) {
opts := minio.PutObjectOptions{
UserMetadata: map[string]string{
"Mtime": fmt.Sprint(time.Now().Unix()),
Expand Down
3 changes: 2 additions & 1 deletion storage/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage

import (
"io"
"os"
"time"

Expand All @@ -21,7 +22,7 @@ type ObjectStorage interface {
DeleteBucket(bucket Bucket) error

GetObject(bucket Bucket, fpath string) (utils.ReaderAtCloser, int64, time.Time, error)
PutObject(bucket Bucket, fpath string, contents utils.ReaderAtCloser, entry *utils.FileEntry) (string, error)
PutObject(bucket Bucket, fpath string, contents io.Reader, entry *utils.FileEntry) (string, error)
DeleteObject(bucket Bucket, fpath string) error
ListObjects(bucket Bucket, dir string, recursive bool) ([]os.FileInfo, error)
}

0 comments on commit 4f5e944

Please sign in to comment.