File tree Expand file tree Collapse file tree 4 files changed +10
-7
lines changed Expand file tree Collapse file tree 4 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export class DownloadManger {
24
24
requestConfig . logger . info ( `Workers Count: ${ this . workers . length } ` )
25
25
26
26
const contentLength = getContentLength ( metadata . headers )
27
- this . rangeProvider = new RangeProvider ( contentLength )
27
+ this . rangeProvider = new RangeProvider ( contentLength , this . requestConfig . segmentStrategy )
28
28
requestConfig . logger . info ( `Content length: ${ contentLength } ` )
29
29
30
30
this . streamer = new DownloadStreamer ( this . rangeProvider . maxRangeIndex , requestConfig ?. init ?. signal )
Original file line number Diff line number Diff line change @@ -6,14 +6,12 @@ const MB = 1024 * 1024
6
6
function defaultSegmentSize ( contentLength : number ) : number {
7
7
if ( contentLength <= 512 * KB ) {
8
8
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 ) ) )
13
11
} else if ( contentLength <= 32 * MB ) {
14
- return 512 * KB
12
+ return Math . ceil ( ( contentLength / 16 ) )
15
13
} else {
16
- return 1 * MB
14
+ return 2 * MB
17
15
}
18
16
}
19
17
Original file line number Diff line number Diff line change @@ -41,4 +41,8 @@ export class GETRequestConfig {
41
41
get chunkCallback ( ) : ChunkCallback {
42
42
return this . fastFetchConfig ?. chunkCallback ?? ( ( ) => undefined )
43
43
}
44
+
45
+ get segmentStrategy ( ) : ( ( contentLength : number ) => Array < [ number , number ] > ) | undefined {
46
+ return this . fastFetchConfig ?. segmentStrategy
47
+ }
44
48
}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export interface FastFetchGetConfig {
10
10
retryDelay ?: number
11
11
logger ?: Partial < Logger >
12
12
chunkCallback ?: ChunkCallback
13
+ segmentStrategy ?: ( contentLength : number ) => Array < [ number , number ] >
13
14
}
14
15
15
16
interface FastFetchGETInit {
You can’t perform that action at this time.
0 commit comments