mirror of
https://github.com/gofiber/storage.git
synced 2025-10-04 08:16:36 +08:00
Fix incorrect sum.
This commit is contained in:
@@ -2,20 +2,26 @@ package s3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
)
|
||||
|
||||
// Additional methods for S3, but not required by gofiber Storage interface.
|
||||
|
||||
// SetWithChecksum sets key with value and checksum.
|
||||
// Key of `checksum` map is algorithm in upper cases, value is the checksum.
|
||||
// Currently only 4 algorithm are supported: `CRC32`, `CRC32C`, `SHA1`, `SHA256`.
|
||||
// Currently only 4 algorithm are supported:
|
||||
// - types.ChecksumAlgorithmCrc32 (`CRC32`)
|
||||
// - types.ChecksumAlgorithmCrc32c (`CRC32C`)
|
||||
// - types.ChecksumAlgorithmSha1 (`SHA1`)
|
||||
// - types.ChecksumAlgorithmSha256 (`SHA256`)
|
||||
//
|
||||
// For more information, see [PutObjectInput](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#PutObjectInput).
|
||||
func (s *Storage) SetWithChecksum(key string, val []byte, checksum map[string][]byte) error {
|
||||
func (s *Storage) SetWithChecksum(key string, val []byte, checksum map[types.ChecksumAlgorithm][]byte) error {
|
||||
if len(key) <= 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -31,14 +37,14 @@ func (s *Storage) SetWithChecksum(key string, val []byte, checksum map[string][]
|
||||
|
||||
for alg, sum := range checksum {
|
||||
switch alg {
|
||||
case "CRC32":
|
||||
poi.ChecksumCRC32 = aws.String(fmt.Sprintf("%x", sum))
|
||||
case "CRC32C":
|
||||
poi.ChecksumCRC32C = aws.String(fmt.Sprintf("%x", sum))
|
||||
case "SHA1":
|
||||
poi.ChecksumSHA1 = aws.String(fmt.Sprintf("%x", sum))
|
||||
case "SHA256":
|
||||
poi.ChecksumSHA256 = aws.String(fmt.Sprintf("%x", sum))
|
||||
case types.ChecksumAlgorithmCrc32:
|
||||
poi.ChecksumCRC32 = aws.String(hex.EncodeToString(sum))
|
||||
case types.ChecksumAlgorithmCrc32c:
|
||||
poi.ChecksumCRC32C = aws.String(hex.EncodeToString(sum))
|
||||
case types.ChecksumAlgorithmSha1:
|
||||
poi.ChecksumSHA1 = aws.String(hex.EncodeToString(sum))
|
||||
case types.ChecksumAlgorithmSha256:
|
||||
poi.ChecksumSHA256 = aws.String(hex.EncodeToString(sum))
|
||||
default:
|
||||
return fmt.Errorf("invalid checksum algorithm: %s", alg)
|
||||
}
|
||||
|
Reference in New Issue
Block a user