Skip to content

Commit 28c14f5

Browse files
committed
fix(lib-storage): respect user-provided partSize option
1 parent ad1514d commit 28c14f5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/lib-storage/src/Upload.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,23 @@ describe(Upload.name, () => {
862862
}).toThrow(`The byte size for part number 1, size 0 does not match expected size ${MOCK_PART_SIZE}`);
863863
});
864864

865+
it("should use the user-specified partSize when provided, taking precedence over calculated partSize", () => {
866+
const bigBuffer = Buffer.alloc(10);
867+
const customPartSize = 50 * 1024 * 1024; // 50 MB
868+
869+
const upload = new Upload({
870+
params: {
871+
Key: "big-file",
872+
Bucket: "bucket",
873+
Body: bigBuffer,
874+
},
875+
partSize: customPartSize,
876+
client: new S3({}),
877+
});
878+
879+
expect((upload as any).partSize).toBe(customPartSize);
880+
});
881+
865882
it("should skip validation for single-part uploads", () => {
866883
const upload = new Upload({
867884
params,

lib/lib-storage/src/Upload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export class Upload extends EventEmitter {
9393
this.bytesUploadedSoFar = 0;
9494
this.abortController = options.abortController ?? new AbortController();
9595

96-
this.partSize = Math.max(Upload.MIN_PART_SIZE, Math.floor((this.totalBytes || 0) / this.MAX_PARTS));
96+
this.partSize =
97+
options.partSize || Math.max(Upload.MIN_PART_SIZE, Math.floor((this.totalBytes || 0) / this.MAX_PARTS));
9798
this.expectedPartsCount = this.totalBytes !== undefined ? Math.ceil(this.totalBytes / this.partSize) : undefined;
9899

99100
this.__validateInput();

0 commit comments

Comments
 (0)