{"id":15376466,"url":"https://github.com/tomayac/fetch-in-chunks","last_synced_at":"2025-03-22T10:11:43.774Z","repository":{"id":242053997,"uuid":"808584775","full_name":"tomayac/fetch-in-chunks","owner":"tomayac","description":"A utility for fetching large files in chunks with support for parallel downloads and progress tracking.","archived":false,"fork":false,"pushed_at":"2024-09-20T08:50:21.000Z","size":53,"stargazers_count":111,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-14T10:06:13.049Z","etag":null,"topics":["chunk","chunked-download","fetch"],"latest_commit_sha":null,"homepage":"https://tomayac.github.io/fetch-in-chunks/demo/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomayac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-31T11:24:48.000Z","updated_at":"2025-03-13T19:37:23.000Z","dependencies_parsed_at":"2024-05-31T11:47:13.473Z","dependency_job_id":"36343915-c1f1-46be-9564-8c9f3447ac1d","html_url":"https://github.com/tomayac/fetch-in-chunks","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":0.07692307692307687,"last_synced_commit":"e0791cd950b5a566c08d17a1921a318ed1adcc04"},"previous_names":["tomayac/fetch-in-chunks"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomayac%2Ffetch-in-chunks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomayac%2Ffetch-in-chunks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomayac%2Ffetch-in-chunks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomayac%2Ffetch-in-chunks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomayac","download_url":"https://codeload.github.com/tomayac/fetch-in-chunks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244937831,"owners_count":20535127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chunk","chunked-download","fetch"],"created_at":"2024-10-01T14:07:40.706Z","updated_at":"2025-03-22T10:11:43.738Z","avatar_url":"https://github.com/tomayac.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fetch-in-chunks\n\nA utility for fetching large files in chunks with support for parallel\ndownloads, progress tracking, and request abortion.\n\n## Installation\n\nInstall the package using npm:\n\n```sh\nnpm install fetch-in-chunks\n```\n\n## Usage\n\n### Importing the Module\n\n```js\nimport fetchInChunks from 'fetch-in-chunks';\n```\n\n### Function Signature\n\n```js\nasync function fetchInChunks(url, options = {})\n```\n\n#### Parameters\n\n- `url` (`string`): The URL of the file to download.\n- `options` (`object`, optional): An object containing additional options.\n  - `options.chunkSize` (`number`, default: `5 * 1024 * 1024`): The size of each\n    chunk to download in bytes.\n  - `options.maxParallelRequests` (`number`, default: `1`): The number of chunks\n    to download in parallel.\n  - `options.progressCallback` (`function`, optional): A callback function that\n    will be called with the number of bytes downloaded and the total size of the\n    file.\n  - `options.signal` (`AbortSignal`, optional): An `AbortSignal` object that can\n    be used to abort the download.\n\n#### Returns\n\n- `Promise\u003cBlob\u003e`: A promise that resolves to a `Blob` containing the downloaded\n  file.\n\n## Example\n\n### Basic Usage\n\n```js\nimport fetchInChunks from 'fetch-in-chunks';\n\nasync function downloadFile() {\n  try {\n    const blob = await fetchInChunks('https://example.com/largefile.zip');\n    return blob;\n  } catch (error) {\n    console.error('Error fetching file:', error);\n  }\n}\n\ndownloadFile();\n```\n\n### With Progress Callback\n\n```js\nimport fetchInChunks from 'fetch-in-chunks';\n\nasync function downloadFileWithProgress() {\n  try {\n    const blob = await fetchInChunks('https://example.com/largefile.zip', {\n      progressCallback: (downloaded, total) =\u003e {\n        console.log(`Downloaded ${((downloaded / total) * 100).toFixed(2)}%`);\n      },\n    });\n    return blob;\n  } catch (error) {\n    console.error('Error fetching file:', error);\n  }\n}\n\ndownloadFileWithProgress();\n```\n\n### With `AbortController`\n\n```js\nimport fetchInChunks from 'fetch-in-chunks';\n\nasync function downloadFileWithAbort() {\n  const controller = new AbortController();\n  const signal = controller.signal;\n\n  try {\n    const blob = await fetchInChunks('https://example.com/largefile.zip', {\n      signal,\n    });\n    return blob;\n  } catch (error) {\n    if (error.name === 'AbortError') {\n      console.log('Download aborted');\n    } else {\n      console.error('Error fetching file:', error);\n    }\n  }\n\n  // To abort the download at any time\n  controller.abort();\n}\n```\n\n## License\n\nThis project is licensed under the Apache 2.0 License. See the `LICENSE` file\nfor details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomayac%2Ffetch-in-chunks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomayac%2Ffetch-in-chunks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomayac%2Ffetch-in-chunks/lists"}