|
| 1 | +package transfermanager |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 5 | +) |
| 6 | + |
| 7 | +const userAgentKey = "s3-transfer" |
| 8 | + |
| 9 | +// defaultMaxUploadParts is the maximum allowed number of parts in a multi-part upload |
| 10 | +// on Amazon S3. |
| 11 | +const defaultMaxUploadParts = 10000 |
| 12 | + |
| 13 | +// defaultPartSizeBytes is the default part size when transferring objects to/from S3 |
| 14 | +const minPartSizeBytes = 1024 * 1024 * 8 |
| 15 | + |
| 16 | +// defaultMultipartUploadThreshold is the default size threshold in bytes indicating when to use multipart upload. |
| 17 | +const defaultMultipartUploadThreshold = 1024 * 1024 * 16 |
| 18 | + |
| 19 | +// defaultTransferConcurrency is the default number of goroutines to spin up when |
| 20 | +// using PutObject(). |
| 21 | +const defaultTransferConcurrency = 5 |
| 22 | + |
| 23 | +// Client provides the API client to make operations call for Amazon Simple |
| 24 | +// Storage Service's Transfer Manager |
| 25 | +// It is safe to call Client methods concurrently across goroutines. |
| 26 | +type Client struct { |
| 27 | + options Options |
| 28 | +} |
| 29 | + |
| 30 | +// New returns an initialized Client from the client Options. Provide |
| 31 | +// more functional options to further configure the Client |
| 32 | +func New(s3Client S3APIClient, opts Options, optFns ...func(*Options)) *Client { |
| 33 | + opts.S3 = s3Client |
| 34 | + for _, fn := range optFns { |
| 35 | + fn(&opts) |
| 36 | + } |
| 37 | + |
| 38 | + resolveConcurrency(&opts) |
| 39 | + resolvePartSizeBytes(&opts) |
| 40 | + resolveChecksumAlgorithm(&opts) |
| 41 | + resolveMultipartUploadThreshold(&opts) |
| 42 | + |
| 43 | + return &Client{ |
| 44 | + options: opts, |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +// NewFromConfig returns a new Client from the provided s3 config |
| 49 | +func NewFromConfig(s3Client S3APIClient, cfg aws.Config, optFns ...func(*Options)) *Client { |
| 50 | + return New(s3Client, Options{}, optFns...) |
| 51 | +} |
0 commit comments