1212using System . Security . AccessControl ;
1313using System . Threading ;
1414using System . Threading . Tasks ;
15+
1516using dotnetCampus . FileDownloader . Utils ;
17+
1618using Microsoft . Extensions . Logging ;
1719
1820namespace dotnetCampus . FileDownloader
@@ -34,14 +36,20 @@ public static class FileDownloaderHelper
3436 /// <param name="bufferLength">缓存的数组长度,默认是 65535 的长度</param>
3537 /// <param name="stepTimeOut">每一步 每一分段下载超时时间 默认 10 秒</param>
3638 /// <returns></returns>
37- public static Task DownloadFileAsync ( string url , FileInfo file ,
39+ public static async Task DownloadFileAsync ( string url , FileInfo file ,
3840 ILogger < SegmentFileDownloader > ? logger = null ,
3941 IProgress < DownloadProgress > ? progress = null , ISharedArrayPool ? sharedArrayPool = null ,
4042 int bufferLength = ushort . MaxValue , TimeSpan ? stepTimeOut = null )
4143 {
42- var segmentFileDownloader = new SegmentFileDownloader ( url , file , logger , progress , sharedArrayPool , bufferLength , stepTimeOut ) ;
44+ #if NETCOREAPP3_1_OR_GREATER
45+ using var segmentFileDownloaderByHttpClient = new SegmentFileDownloaderByHttpClient ( url , file , httpClient : null , logger , progress , sharedArrayPool , bufferLength , stepTimeOut ) ;
46+ await segmentFileDownloaderByHttpClient . DownloadFileAsync ( ) ;
47+ #else
48+ var segmentFileDownloader =
49+ new SegmentFileDownloader ( url , file , logger , progress , sharedArrayPool , bufferLength , stepTimeOut ) ;
4350
44- return segmentFileDownloader . DownloadFileAsync ( ) ;
51+ await segmentFileDownloader . DownloadFileAsync ( ) ;
52+ #endif
4553 }
4654
4755 /// <summary>
@@ -79,10 +87,10 @@ public static async Task<FileInfo> DownloadFileToFolderAsync(string url, Directo
7987 var downloadFile = new FileInfo ( Path . Combine ( tempFolder . FullName , fileName ) ) ;
8088
8189#if NETCOREAPP3_1_OR_GREATER
82- using var segmentFileDownloader = new InnerSegmentFileDownloaderByHttpClient ( url , downloadFile , httpClient : null ,
83- logger , progress , sharedArrayPool , bufferLength , stepTimeOut ) ;
90+ using var segmentFileDownloader = new InnerSegmentFileDownloaderByHttpClient ( url , downloadFile , httpClient : null ,
91+ logger , progress , sharedArrayPool , bufferLength , stepTimeOut ) ;
8492
85- await segmentFileDownloader . DownloadFileAsync ( ) ;
93+ await segmentFileDownloader . DownloadFileAsync ( ) ;
8694
8795 // 下载完成了之后,尝试移动文件夹
8896 // 优先使用服务器返回的文件名
0 commit comments