From 8b598cddbba4102c8bd2256f0f907e4dcc9698ed Mon Sep 17 00:00:00 2001 From: Miraclx Date: Sat, 4 Jul 2020 01:16:41 +0100 Subject: [PATCH] Fallback to 1 or 5 chunks as necessary if chunks are larger than the size --- README.md | 2 +- lib/index.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4312ed5..87df167 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ The purpose of the hasher is to check the integrity of the merged chunks while w ### XGETOptions `extends` [AxiosOpts][]: [`Object`][object] -- `chunks`: <[number][]> Number of chunked-simultaneous downloads. **Default**: `5` +- `chunks`: <[number][]> Maximum number of non-overlapping chunk connections. **Default**: `5` - `retries`: <[number][]> Number of retries for each chunk. **Default**: `5` - `timeout`: <[number][]> Network response timeout (ms). **Default**: `20000` - `start`: <[number][]> Position to start feeding the stream from. **Default**: `0` diff --git a/lib/index.js b/lib/index.js index 54f35f8..50c5f78 100644 --- a/lib/index.js +++ b/lib/index.js @@ -111,6 +111,7 @@ async function xHeadData(store, opts) { }); store.start = !acceptsRanges ? 0 : typeof offset === 'number' ? offset : store.start; if (!Number.isFinite(store.size)) store.size = store.totalSize - store.start; + if (store.size < store.chunks) store.chunks = store.size < 5 ? 1 : 5; const spec = parseSplitSpec(store.size, store.chunks); store.chunkStack = buildChunks( store.url,