Skip to content

Commit c735f54

Browse files
committed
feat: implement multipart upload based on file size
1 parent 0219dd7 commit c735f54

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

src/commands/upload-file.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,38 @@ export default class UploadFile extends Command {
8282
linewrap: true,
8383
});
8484
progressBar.start(100, 0);
85-
const [uploadPromise, abortable] = await networkFacade.uploadFromStream(
86-
user.bucket,
87-
user.mnemonic,
88-
stats.size,
89-
fileStream,
90-
{
85+
86+
const minimumMultipartThreshold = 100 * 1024 * 1024;
87+
const useMultipart = stats.size > minimumMultipartThreshold;
88+
const partSize = 30 * 1024 * 1024;
89+
const parts = Math.ceil(stats.size / partSize);
90+
91+
let uploadOperation: Promise<
92+
[
93+
Promise<{
94+
fileId: string;
95+
hash: Buffer;
96+
}>,
97+
AbortController,
98+
]
99+
>;
100+
101+
if (useMultipart) {
102+
uploadOperation = networkFacade.uploadMultipartFromStream(user.bucket, user.mnemonic, stats.size, fileStream, {
103+
parts,
91104
progressCallback: (progress) => {
92105
progressBar.update(progress * 0.99);
93106
},
94-
},
95-
);
107+
});
108+
} else {
109+
uploadOperation = networkFacade.uploadFromStream(user.bucket, user.mnemonic, stats.size, fileStream, {
110+
progressCallback: (progress) => {
111+
progressBar.update(progress * 0.99);
112+
},
113+
});
114+
}
115+
116+
const [uploadPromise, abortable] = await uploadOperation;
96117

97118
process.on('SIGINT', () => {
98119
abortable.abort('SIGINT received');

0 commit comments

Comments
 (0)