Skip to content

Commit 7db2f17

Browse files
authored
@tus/s3-store: add maxMultipartParts option (#712)
1 parent 2da6a84 commit 7db2f17

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

.changeset/tricky-emus-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tus/s3-store": minor
3+
---
4+
5+
Add `maxMultipartParts` option. This can be used when using S3-compatible storage provider with different part number limitations.

packages/s3-store/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export type Options = {
3737
* Can not be lower than 5MiB or more than 5GiB.
3838
*/
3939
minPartSize?: number
40+
/**
41+
* The maximum number of parts allowed in a multipart upload. Defaults to 10,000.
42+
*/
43+
maxMultipartParts?: number
4044
useTags?: boolean
4145
maxConcurrentPartUploads?: number
4246
cache?: KvStore<MetadataValue>
@@ -97,13 +101,13 @@ export class S3Store extends DataStore {
97101
protected expirationPeriodInMilliseconds = 0
98102
protected useTags = true
99103
protected partUploadSemaphore: Semaphore
100-
public maxMultipartParts = 10_000 as const
104+
public maxMultipartParts = 10_000
101105
public minPartSize = 5_242_880 // 5MiB
102106
public maxUploadSize = 5_497_558_138_880 as const // 5TiB
103107

104108
constructor(options: Options) {
105109
super()
106-
const {partSize, minPartSize, s3ClientConfig} = options
110+
const {maxMultipartParts, partSize, minPartSize, s3ClientConfig} = options
107111
const {bucket, ...restS3ClientConfig} = s3ClientConfig
108112
this.extensions = [
109113
'creation',
@@ -117,6 +121,9 @@ export class S3Store extends DataStore {
117121
if (minPartSize) {
118122
this.minPartSize = minPartSize
119123
}
124+
if (maxMultipartParts) {
125+
this.maxMultipartParts = maxMultipartParts
126+
}
120127
this.expirationPeriodInMilliseconds = options.expirationPeriodInMilliseconds ?? 0
121128
this.useTags = options.useTags ?? true
122129
this.cache = options.cache ?? new MemoryKvStore<MetadataValue>()

packages/s3-store/test/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ describe('S3DataStore', () => {
278278
}
279279
})
280280

281+
it('should use default maxMultipartParts when not specified', function () {
282+
const store = new S3Store({
283+
s3ClientConfig,
284+
})
285+
assert.equal(store.maxMultipartParts, 10000)
286+
})
287+
288+
it('should use custom maxMultipartParts when specified', function () {
289+
const customMaxParts = 5000
290+
const store = new S3Store({
291+
s3ClientConfig,
292+
maxMultipartParts: customMaxParts,
293+
})
294+
assert.equal(store.maxMultipartParts, customMaxParts)
295+
})
296+
281297
shared.shouldHaveStoreMethods()
282298
shared.shouldCreateUploads()
283299
shared.shouldRemoveUploads() // Termination extension

0 commit comments

Comments
 (0)