Skip to content

Commit 1aa0ae7

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

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-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: 59 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>
@@ -50,6 +66,8 @@ public abstract class BaseDownloadRequest
5066
private string ifMatch;
5167
private string ifNoneMatch;
5268
private ResponseHeaderOverrides responseHeaders;
69+
private long? partSize;
70+
private MultipartDownloadType multipartDownloadType = MultipartDownloadType.PART;
5371

5472
/// <summary>
5573
/// Gets or sets the name of the bucket.
@@ -330,5 +348,45 @@ public ResponseHeaderOverrides ResponseHeaderOverrides
330348
this.responseHeaders = value;
331349
}
332350
}
351+
352+
/// <summary>
353+
/// Gets or sets the part size of the download in bytes.
354+
/// The downloaded file will be divided into
355+
/// parts the size specified and
356+
/// downloaded from Amazon S3 individually.
357+
/// This is used when MultipartDownloadType is set to RANGE.
358+
/// </summary>
359+
/// <value>
360+
/// The part size of the download.
361+
/// </value>
362+
public long PartSize
363+
{
364+
get { return this.partSize.GetValueOrDefault(); }
365+
set { this.partSize = value; }
366+
}
367+
368+
/// <summary>
369+
/// Checks if PartSize property is set.
370+
/// </summary>
371+
/// <returns>true if PartSize property is set.</returns>
372+
internal bool IsSetPartSize()
373+
{
374+
return this.partSize.HasValue;
375+
}
376+
377+
/// <summary>
378+
/// Gets or sets the type of multipart download to use.
379+
/// PART: Uses part GET with original part sizes from upload (ignores PartSize)
380+
/// RANGE: Uses ranged GET with PartSize to determine ranges
381+
/// Default is PART
382+
/// </summary>
383+
/// <value>
384+
/// The multipart download type.
385+
/// </value>
386+
public MultipartDownloadType MultipartDownloadType
387+
{
388+
get { return this.multipartDownloadType; }
389+
set { this.multipartDownloadType = value; }
390+
}
333391
}
334-
}
392+
}

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)