|
- package s3
-
- import (
- "context"
- "io"
-
- "github.com/aws/aws-sdk-go-v2/aws"
- "github.com/aws/aws-sdk-go-v2/service/s3"
- clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
- "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types"
- )
-
- type DirReader struct {
- cli *s3.Client
- bucket string
- rootPath clitypes.JPath
- marker *string
- curInfos []types.DirEntry
- eof bool
- }
-
- func (r *DirReader) Next() (types.DirEntry, error) {
- if len(r.curInfos) > 0 {
- e := r.curInfos[0]
- r.curInfos = r.curInfos[1:]
- return e, nil
- }
- if r.eof {
- return types.DirEntry{}, io.EOF
- }
-
- resp, err := r.cli.ListObjects(context.Background(), &s3.ListObjectsInput{
- Bucket: aws.String(r.bucket),
- Prefix: aws.String(r.rootPath.String()),
- Marker: r.marker,
- })
- if err != nil {
- return types.DirEntry{}, err
- }
-
- for _, obj := range resp.Contents {
- key := clitypes.PathFromJcsPathString(*obj.Key)
-
- r.curInfos = append(r.curInfos, types.DirEntry{
- Path: key,
- Size: *obj.Size,
- ModTime: *obj.LastModified,
- IsDir: false,
- })
- }
-
- if !*resp.IsTruncated {
- r.eof = true
- }
- r.marker = resp.NextMarker
-
- return r.Next()
- }
- func (r *DirReader) Close() {
-
- }
|