cdm_data_loaders.utils.file_transfer.s3.transfer_config ¶
Compute a safe boto3 TransferConfig for a given (or unknown) file size.
Kept free of any S3/HTTP I/O so the chunksize arithmetic can be unit tested directly against plain integers.
compute_multipart_chunksize ¶
compute_multipart_chunksize(
file_size: int | None,
requested_chunksize: int | None = None,
) -> int
Compute a multipart chunksize that will not exceed S3's 10,000-part limit.
If file_size would require more than S3_MAX_PARTS parts at
requested_chunksize, the chunksize is scaled up just enough to bring
the part count back within S3's limit; a warning is logged in that case,
since it usually indicates an unusually large file. The result is always
at least S3_MIN_PART_SIZE, since S3 rejects smaller multipart parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_size
|
int | None
|
size of the file to be uploaded, in bytes, or None if unknown |
required |
requested_chunksize
|
int | None
|
chunksize to use as a starting point, in
bytes, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
int
|
a chunksize, in bytes, safe to use as |
Source code in src/cdm_data_loaders/utils/file_transfer/s3/transfer_config.py
build_transfer_config ¶
Build a boto3.s3.transfer.TransferConfig sized appropriately for file_size.
Always computes a safe multipart_chunksize via compute_multipart_chunksize,
using any explicitly requested multipart_chunksize in overrides as the
starting point (and scaling it up if necessary), rather than silently
ignoring the caller's preference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_size
|
int | None
|
size of the file to be uploaded, in bytes, or None if unknown ahead of time (e.g. no Content-Length header available) |
required |
overrides
|
Any
|
any other |
{}
|
Returns:
| Type | Description |
|---|---|
TransferConfig
|
a TransferConfig with a chunksize guaranteed not to exceed
S3's 10,000-part limit for a file of |