-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refs #32: refactor usecase and primitive package * refs #32: implement file transfer * refs #32: rename convertors * refs #32: change read size
- Loading branch information
Showing
54 changed files
with
800 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package minio | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/CityBear3/satellite/internal/domain/primitive" | ||
"github.com/CityBear3/satellite/internal/domain/primitive/archive" | ||
"github.com/minio/minio-go/v7" | ||
) | ||
|
||
type FileTransfer struct { | ||
client *minio.Client | ||
bucketName string | ||
} | ||
|
||
func NewFileTransfer(client *minio.Client, bucketName string) *FileTransfer { | ||
return &FileTransfer{ | ||
client: client, | ||
bucketName: bucketName, | ||
} | ||
} | ||
|
||
func (f FileTransfer) Save( | ||
ctx context.Context, | ||
archiveID primitive.ID, | ||
contentType archive.ContentType, | ||
data archive.Data, | ||
) error { | ||
if _, err := f.client.PutObject( | ||
ctx, f.bucketName, | ||
fmt.Sprintf("%s.%s", archiveID.String(), contentType.GetExt()), | ||
bytes.NewReader(data.Chunks), | ||
int64(data.Size.Value()), minio.PutObjectOptions{}, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (f FileTransfer) GetFile(ctx context.Context, archiveID primitive.ID, contentType archive.ContentType) (archive.Data, error) { | ||
object, err := f.client.GetObject( | ||
ctx, | ||
f.bucketName, | ||
fmt.Sprintf("%s.%s", archiveID.String(), contentType.GetExt()), | ||
minio.GetObjectOptions{}, | ||
) | ||
|
||
var buf []byte | ||
for { | ||
tmp := make([]byte, 1e6) | ||
_, err := object.Read(tmp) | ||
if err == io.EOF { | ||
break | ||
} | ||
|
||
if err != nil { | ||
return archive.Data{}, err | ||
} | ||
|
||
buf = append(buf, tmp...) | ||
} | ||
|
||
data, err := archive.NewData(buf) | ||
if err != nil { | ||
return archive.Data{}, err | ||
} | ||
|
||
return data, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.