Skip to content

Commit 3daa89d

Browse files
committed
response as DownloadManager field
1 parent 60fcc5c commit 3daa89d

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/get/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function GET (input: FetchInput, init?: GETInit): Promise<Response>
1515
}
1616

1717
const manager = new DownloadManger(requestConfig, metadata)
18-
return await manager.fetch()
18+
return manager.response
1919
} catch {
2020
requestConfig.logger.error('Fallback to normal fetch')
2121
// fallback to normal fetch

src/get/manager/DownloadManger.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { DownloadStreamer } from './DownloadStreamer'
66
import type { GETRequestConfig } from '../request'
77

88
export class DownloadManger {
9-
readonly metadata: Metadata
10-
readonly requestConfig: GETRequestConfig
11-
readonly workers: DownloadWorker[]
12-
readonly rangeProvider: RangeProvider
13-
readonly streamer: DownloadStreamer
9+
private readonly metadata: Metadata
10+
private readonly requestConfig: GETRequestConfig
11+
private readonly workers: DownloadWorker[]
12+
private readonly rangeProvider: RangeProvider
13+
private readonly streamer: DownloadStreamer
14+
readonly response: Response
1415

1516
constructor (requestConfig: GETRequestConfig, metadata: Metadata) {
1617
this.requestConfig = requestConfig
@@ -25,15 +26,13 @@ export class DownloadManger {
2526
requestConfig.logger.info(`Content length: ${contentLength}`)
2627

2728
this.streamer = new DownloadStreamer(this.rangeProvider.maxRangeIndex, requestConfig?.init?.signal)
28-
}
2929

30-
async fetch (): Promise<Response> {
3130
void this.startFetching()
32-
return new Response(this.streamer.ReadableStream, this.metadata)
31+
this.response = new Response(this.streamer.ReadableStream, this.metadata)
3332
}
3433

3534
// start fetching
36-
async startFetching (): Promise<void> {
35+
private async startFetching (): Promise<void> {
3736
this.requestConfig.logger.info('Start fetching.')
3837

3938
const promises = this.workers.map(async (worker, idx) =>

0 commit comments

Comments
 (0)