* Process transform result (async).
( result: AsyncTransformResult )
| 213 | /** |
| 214 | * Process transform result (async). |
| 215 | */ |
| 216 | async function* processTransformResultAsync( |
| 217 | result: AsyncTransformResult |
| 218 | ): AsyncGenerator<Uint8Array[]> { |
| 219 | // Handle Promise |
| 220 | if (result instanceof Promise) { |
| 221 | const resolved = await result; |
| 222 | yield* processTransformResultAsync(resolved); |
| 223 | return; |
| 224 | } |
| 225 | if (result === null) { |
| 226 | return; |
| 227 | } |
| 228 | if (Array.isArray(result) && (result.length === 0 || result[0] instanceof Uint8Array)) { |
| 229 | // Fast path: Uint8Array[] |
| 230 | if (result.length > 0) { |
| 231 | yield result as Uint8Array[]; |
| 232 | } |
| 233 | return; |
| 234 | } |
| 235 | // Check for async iterable/generator first |
| 236 | if (isAsyncIterable(result)) { |
| 237 | const batch: Uint8Array[] = []; |
| 238 | for await (const item of result) { |
| 239 | // Fast path: item is already Uint8Array |
| 240 | if (item instanceof Uint8Array) { |
| 241 | batch.push(item); |
| 242 | continue; |
| 243 | } |
| 244 | // Slow path: flatten the item |
| 245 | for await (const chunk of flattenTransformYieldAsync(item as TransformYield)) { |
| 246 | batch.push(chunk); |
| 247 | } |
| 248 | } |
| 249 | if (batch.length > 0) { |
| 250 | yield batch; |
| 251 | } |
| 252 | return; |
| 253 | } |
| 254 | // Sync Iterable or Generator |
| 255 | if (isSyncIterable(result)) { |
| 256 | const batch: Uint8Array[] = []; |
| 257 | for (const item of result) { |
| 258 | // Fast path: item is already Uint8Array |
| 259 | if (item instanceof Uint8Array) { |
| 260 | batch.push(item); |
| 261 | continue; |
| 262 | } |
| 263 | // Slow path: flatten the item |
| 264 | for await (const chunk of flattenTransformYieldAsync(item as TransformYield)) { |
| 265 | batch.push(chunk); |
| 266 | } |
| 267 | } |
| 268 | if (batch.length > 0) { |
| 269 | yield batch; |
| 270 | } |
| 271 | return; |
| 272 | } |
no test coverage detected