Skip to content

Commit 67bb12f

Browse files
committed
Update TransferUtilityConfig and BaseDownloadRequest to add multi part download config options
1 parent 6e1ebab commit 67bb12f

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "S3",
5+
"type": "patch",
6+
"changeLogMessages": [
7+
"Added MaxInMemoryParts property to TransferUtilityConfig for controlling memory usage during multipart downloads",
8+
"Added PartSize property to BaseDownloadRequest for configuring multipart download part sizes",
9+
"Added MultipartDownloadType enum and property to BaseDownloadRequest for selecting download strategy"
10+
]
11+
}
12+
]
13+
}

sdk/src/Services/S3/Custom/Transfer/BaseDownloadRequest.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@
2828

2929
namespace Amazon.S3.Transfer
3030
{
31+
/// <summary>
32+
/// Specifies the strategy for multipart downloads
33+
/// </summary>
34+
public enum MultipartDownloadType
35+
{
36+
/// <summary>
37+
/// Use part-based downloads with original upload part boundaries
38+
/// </summary>
39+
PART,
40+
41+
/// <summary>
42+
/// Use range-based downloads with configurable part sizes
43+
/// </summary>
44+
RANGE
45+
}
46+
3147
/// <summary>
3248
/// The base class for requests that return Amazon S3 objects.
3349
/// </summary>
@@ -51,6 +67,10 @@ public abstract class BaseDownloadRequest
5167
private string ifNoneMatch;
5268
private ResponseHeaderOverrides responseHeaders;
5369

70+
// Optional part size override (defaults to 8MB per SEP recommendations)
71+
private long? partSize;
72+
private MultipartDownloadType multipartDownloadType = MultipartDownloadType.PART;
73+
5474
/// <summary>
5575
/// Gets or sets the name of the bucket.
5676
/// </summary>
@@ -330,5 +350,46 @@ public ResponseHeaderOverrides ResponseHeaderOverrides
330350
this.responseHeaders = value;
331351
}
332352
}
353+
354+
/// <summary>
355+
/// Gets or sets the part size of the download in bytes.
356+
/// The downloaded file will be divided into
357+
/// parts the size specified and
358+
/// downloaded from Amazon S3 individually.
359+
/// This is used when MultipartDownloadType is set to RANGE.
360+
/// Default is 8MB per SEP recommendations.
361+
/// </summary>
362+
/// <value>
363+
/// The part size of the download.
364+
/// </value>
365+
public long PartSize
366+
{
367+
get { return this.partSize.GetValueOrDefault(); }
368+
set { this.partSize = value; }
369+
}
370+
371+
/// <summary>
372+
/// Checks if PartSize property is set.
373+
/// </summary>
374+
/// <returns>true if PartSize property is set.</returns>
375+
internal bool IsSetPartSize()
376+
{
377+
return this.partSize.HasValue;
378+
}
379+
380+
/// <summary>
381+
/// Gets or sets the type of multipart download to use.
382+
/// PART: Uses part GET with original part sizes from upload (ignores PartSize)
383+
/// RANGE: Uses ranged GET with PartSize to determine ranges
384+
/// Default is PART
385+
/// </summary>
386+
/// <value>
387+
/// The multipart download type.
388+
/// </value>
389+
public MultipartDownloadType MultipartDownloadType
390+
{
391+
get { return this.multipartDownloadType; }
392+
set { this.multipartDownloadType = value; }
393+
}
333394
}
334-
}
395+
}

sdk/src/Services/S3/Custom/Transfer/TransferUtilityConfig.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public partial class TransferUtilityConfig
4242
{
4343
long _minSizeBeforePartUpload = 16 * (long)Math.Pow(2, 20);
4444
int _concurrentServiceRequests;
45+
int _maxInMemoryParts = 1024; // When combined with the default part size of 8MB, we get 8GB of memory being utilized as the default.
4546

4647
/// <summary>
4748
/// Default constructor.
@@ -81,5 +82,21 @@ public int ConcurrentServiceRequests
8182
this._concurrentServiceRequests = value;
8283
}
8384
}
85+
86+
/// <summary>
87+
/// Gets or sets the maximum number of parts to buffer in memory during multipart downloads.
88+
/// The default value is 1024.
89+
/// </summary>
90+
public int MaxInMemoryParts
91+
{
92+
get { return this._maxInMemoryParts; }
93+
set
94+
{
95+
if (value < 1)
96+
value = 1;
97+
98+
this._maxInMemoryParts = value;
99+
}
100+
}
84101
}
85102
}

0 commit comments

Comments
 (0)