( readable: NodeJS.ReadableStream | null | undefined, writable: WritableStream<Uint8Array>, abortSignal?: AbortSignal )
| 233 | } |
| 234 | |
| 235 | async function pipeReadableToWebWritable( |
| 236 | readable: NodeJS.ReadableStream | null | undefined, |
| 237 | writable: WritableStream<Uint8Array>, |
| 238 | abortSignal?: AbortSignal |
| 239 | ): Promise<void> { |
| 240 | if (!readable) { |
| 241 | throw new Error("Missing git bundle output stream"); |
| 242 | } |
| 243 | |
| 244 | const writer = writable.getWriter(); |
| 245 | try { |
| 246 | for await (const chunk of readable) { |
| 247 | if (abortSignal?.aborted) { |
| 248 | throw new Error("Bundle creation aborted"); |
| 249 | } |
| 250 | const data = |
| 251 | typeof chunk === "string" |
| 252 | ? Buffer.from(chunk) |
| 253 | : chunk instanceof Uint8Array |
| 254 | ? chunk |
| 255 | : Buffer.from(chunk); |
| 256 | await writer.write(data); |
| 257 | } |
| 258 | await writer.close(); |
| 259 | } catch (error) { |
| 260 | try { |
| 261 | await writer.abort(error); |
| 262 | } catch { |
| 263 | writer.releaseLock(); |
| 264 | } |
| 265 | throw error; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | function createAbortController( |
| 270 | timeoutMs: number | undefined, |
no test coverage detected