Skip to content

Commit 382a257

Browse files
Arlen22Copilot
andcommitted
Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4fc4980 commit 382a257

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/multipart-parser/src/lib/multipart.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,21 @@ export interface ParseMultipartOptions {
5555
*/
5656
maxFileSize?: number
5757

58+
/**
59+
* If this is true, or not defined, use MultipartContentPart class, which includes a contents array and getters referencing it, and stores the entire file in the contents array in memory.
60+
*
61+
* If this is false, use the MultipartPart class, which only has header related fields. The append method must be overriden in the onCreatePart callback to receive each chunk and process it as desired.
62+
*
63+
*/
5864
useContentPart?: boolean
65+
/**
66+
* A callback called for each multipart part created. This is called immediately after the header is parsed, and before any body chunks are processed, including the partial chunk after the header.
67+
*
68+
* If you want to immediately write chunks to the file system, set useContentPart to false, and then set the part.append method of each part this callback is called with. part.append will be called with each chunk, including partial chunks, after the returned promise resolves, and before the iterator yields the completed chunk.
69+
*
70+
* This callback and part.append are both awaited.
71+
*
72+
*/
5973
onCreatePart?(part: MultipartPart): Promise<void> | void
6074
}
6175

@@ -265,7 +279,7 @@ export class MultipartParser {
265279
throw new MaxHeaderSizeExceededError(this.maxHeaderSize)
266280
}
267281

268-
const header = chunk.subarray(index, headerEndIndex);
282+
const header = chunk.subarray(index, headerEndIndex)
269283
this.#currentPart = this.#useContentPart
270284
? new MultipartContentPart(header, [])
271285
: new MultipartPart(header)
@@ -336,7 +350,7 @@ export class MultipartPart {
336350
this.#header = header
337351
}
338352

339-
async append(chunk: Uint8Array) {
353+
async append(chunk: Uint8Array): Promise<void> {
340354
throw new Error("Not implemented. Please assign or override this method.");
341355
}
342356

0 commit comments

Comments
 (0)