Skip to content

Commit 88ac853

Browse files
committed
pass segmentStrategy
1 parent f42dcc5 commit 88ac853

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/get/manager/DownloadManger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class DownloadManger {
2424
requestConfig.logger.info(`Workers Count: ${this.workers.length}`)
2525

2626
const contentLength = getContentLength(metadata.headers)
27-
this.rangeProvider = new RangeProvider(contentLength)
27+
this.rangeProvider = new RangeProvider(contentLength, this.requestConfig.segmentStrategy)
2828
requestConfig.logger.info(`Content length: ${contentLength}`)
2929

3030
this.streamer = new DownloadStreamer(this.rangeProvider.maxRangeIndex, requestConfig?.init?.signal)

src/get/range/segmentStrategy.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ const MB = 1024 * 1024
66
function defaultSegmentSize (contentLength: number): number {
77
if (contentLength <= 512 * KB) {
88
return contentLength
9-
} else if (contentLength <= 4 * MB) {
10-
return 128 * KB
11-
} else if (contentLength <= 16 * MB) {
12-
return 256 * KB
9+
} else if (contentLength <= 8 * MB) {
10+
return Math.ceil(Math.max(512 * KB, (contentLength / 8)))
1311
} else if (contentLength <= 32 * MB) {
14-
return 512 * KB
12+
return Math.ceil((contentLength / 16))
1513
} else {
16-
return 1 * MB
14+
return 2 * MB
1715
}
1816
}
1917

src/get/request/RequestConfig.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ export class GETRequestConfig {
4141
get chunkCallback (): ChunkCallback {
4242
return this.fastFetchConfig?.chunkCallback ?? (() => undefined)
4343
}
44+
45+
get segmentStrategy (): ((contentLength: number) => Array<[number, number]>) | undefined {
46+
return this.fastFetchConfig?.segmentStrategy
47+
}
4448
}

src/get/request/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface FastFetchGetConfig {
1010
retryDelay?: number
1111
logger?: Partial<Logger>
1212
chunkCallback?: ChunkCallback
13+
segmentStrategy?: (contentLength: number) => Array<[number, number]>
1314
}
1415

1516
interface FastFetchGETInit {

0 commit comments

Comments
 (0)