(url: string, method: string, headers: Record<string, string>, parts: Uint8Array[], contentType?: string)
| 50 | } |
| 51 | |
| 52 | function streamFetch(url: string, method: string, headers: Record<string, string>, parts: Uint8Array[], contentType?: string): Promise<Response> { |
| 53 | const total = parts.reduce((sum, part) => sum + part.length, 0); |
| 54 | const finalHeaders: Record<string, string> = { ...headers, "Content-Length": String(total) }; |
| 55 | if (contentType) finalHeaders["Content-Type"] = contentType; |
| 56 | |
| 57 | const controller = new AbortController(); |
| 58 | activeUploadController = controller; |
| 59 | |
| 60 | return fetch(url, { |
| 61 | method, |
| 62 | headers: finalHeaders, |
| 63 | body: progressStream(parts), |
| 64 | duplex: "half", |
| 65 | signal: controller.signal |
| 66 | } as RequestInit & { duplex: "half"; }).finally(() => { |
| 67 | if (activeUploadController === controller) activeUploadController = null; |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | function multipartFetch(url: string, fields: Record<string, string>, fileFieldName: string, fileBuffer: ArrayBuffer, filename: string, headers: Record<string, string> = {}): Promise<Response> { |
| 72 | const boundary = `----BigFileUpload${Date.now().toString(16)}${Math.random().toString(16).slice(2)}`; |
no test coverage detected