This commit is contained in:
withchao
2023-03-30 14:19:58 +08:00
parent 8843933d45
commit ee712593d1
5 changed files with 256 additions and 155 deletions
+29
View File
@@ -2,6 +2,7 @@ package obj
import (
"context"
"io"
"net/http"
"time"
)
@@ -29,6 +30,30 @@ type ObjectInfo struct {
Hash string
}
type SizeReader interface {
io.ReadCloser
Size() int64
}
func NewSizeReader(r io.ReadCloser, size int64) SizeReader {
if r == nil {
return nil
}
return &sizeReader{
size: size,
ReadCloser: r,
}
}
type sizeReader struct {
size int64
io.ReadCloser
}
func (r *sizeReader) Size() int64 {
return r.size
}
type Interface interface {
// Name 存储名字
Name() string
@@ -58,4 +83,8 @@ type Interface interface {
IsNotFound(err error) bool
// CheckName 检查名字是否可用
CheckName(name string) error
// PutObject 上传文件
PutObject(ctx context.Context, info *BucketObject, reader io.Reader, size int64) (*ObjectInfo, error)
// GetObject 下载文件
GetObject(ctx context.Context, info *BucketObject) (SizeReader, error)
}