(
url: RequestInfo, options: FileChunkIteratorOptions = {},
fetchFunc?: Function)
| 27 | * yet reliably provide a reader stream for the response body. |
| 28 | */ |
| 29 | export async function urlChunkIterator( |
| 30 | url: RequestInfo, options: FileChunkIteratorOptions = {}, |
| 31 | fetchFunc?: Function) { |
| 32 | let urlString; |
| 33 | let requestInit; |
| 34 | if ((typeof url) === 'string') { |
| 35 | urlString = url as string; |
| 36 | } else { |
| 37 | urlString = (url as Request).url; |
| 38 | requestInit = getRequestInitFromRequest(url as Request); |
| 39 | } |
| 40 | const response = await (fetchFunc || util.fetch)(urlString, requestInit); |
| 41 | if (response.ok) { |
| 42 | const uint8Array = new Uint8Array(await response.arrayBuffer()); |
| 43 | return new FileChunkIterator(uint8Array, options); |
| 44 | } else { |
| 45 | throw new Error(response.statusText); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Generate RequestInit from Request to match tf.util.fetch signature. |
| 50 | const getRequestInitFromRequest = (request: Request) => { |
no test coverage detected
searching dependent graphs…