(value: ToFileInput)
| 415 | }; |
| 416 | |
| 417 | async function getBytes(value: ToFileInput): Promise<Array<BlobPart>> { |
| 418 | let parts: Array<BlobPart> = []; |
| 419 | if ( |
| 420 | typeof value === "string" || |
| 421 | ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc. |
| 422 | value instanceof ArrayBuffer |
| 423 | ) { |
| 424 | parts.push(value); |
| 425 | } else if (isBlobLike(value)) { |
| 426 | parts.push(await value.arrayBuffer()); |
| 427 | } else if ( |
| 428 | isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc. |
| 429 | ) { |
| 430 | for await (const chunk of value) { |
| 431 | parts.push(chunk as BlobPart); // TODO, consider validating? |
| 432 | } |
| 433 | } else { |
| 434 | throw new Error( |
| 435 | `Unexpected data type: ${typeof value}; constructor: ${value?.constructor |
| 436 | ?.name}; props: ${propsForError(value)}` |
| 437 | ); |
| 438 | } |
| 439 | |
| 440 | return parts; |
| 441 | } |
| 442 | |
| 443 | function propsForError(value: any): string { |
| 444 | const props = Object.getOwnPropertyNames(value); |
no test coverage detected
searching dependent graphs…