-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tianyi Wang
committed
Oct 31, 2024
1 parent
afdb785
commit 734b574
Showing
13 changed files
with
2,776 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package transfermanager | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
) | ||
|
||
// S3APIClient defines an interface doing S3 client side operations for transfer manager | ||
type S3APIClient interface { | ||
PutObject(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error) | ||
UploadPart(context.Context, *s3.UploadPartInput, ...func(*s3.Options)) (*s3.UploadPartOutput, error) | ||
CreateMultipartUpload(context.Context, *s3.CreateMultipartUploadInput, ...func(*s3.Options)) (*s3.CreateMultipartUploadOutput, error) | ||
CompleteMultipartUpload(context.Context, *s3.CompleteMultipartUploadInput, ...func(*s3.Options)) (*s3.CompleteMultipartUploadOutput, error) | ||
AbortMultipartUpload(context.Context, *s3.AbortMultipartUploadInput, ...func(*s3.Options)) (*s3.AbortMultipartUploadOutput, error) | ||
} |
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,51 @@ | ||
package transfermanager | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
) | ||
|
||
const userAgentKey = "s3-transfer" | ||
|
||
// defaultMaxUploadParts is the maximum allowed number of parts in a multi-part upload | ||
// on Amazon S3. | ||
const defaultMaxUploadParts = 10000 | ||
|
||
// defaultPartSizeBytes is the default part size when transferring objects to/from S3 | ||
const minPartSizeBytes = 1024 * 1024 * 8 | ||
|
||
// defaultMultipartUploadThreshold is the default size threshold in bytes indicating when to use multipart upload. | ||
const defaultMultipartUploadThreshold = 1024 * 1024 * 16 | ||
|
||
// defaultTransferConcurrency is the default number of goroutines to spin up when | ||
// using PutObject(). | ||
const defaultTransferConcurrency = 5 | ||
|
||
// Client provides the API client to make operations call for Amazon Simple | ||
// Storage Service's Transfer Manager | ||
// It is safe to call Client methods concurrently across goroutines. | ||
type Client struct { | ||
options Options | ||
} | ||
|
||
// New returns an initialized Client from the client Options. Provide | ||
// more functional options to further configure the Client | ||
func New(s3Client S3APIClient, opts Options, optFns ...func(*Options)) *Client { | ||
opts.S3 = s3Client | ||
for _, fn := range optFns { | ||
fn(&opts) | ||
} | ||
|
||
resolveConcurrency(&opts) | ||
resolvePartSizeBytes(&opts) | ||
resolveChecksumAlgorithm(&opts) | ||
resolveMultipartUploadThreshold(&opts) | ||
|
||
return &Client{ | ||
options: opts, | ||
} | ||
} | ||
|
||
// NewFromConfig returns a new Client from the provided s3 config | ||
func NewFromConfig(s3Client S3APIClient, cfg aws.Config, optFns ...func(*Options)) *Client { | ||
return New(s3Client, Options{}, optFns...) | ||
} |
Oops, something went wrong.