88using System . IO . Compression ;
99using System . Linq ;
1010using System . Net ;
11+ using System . Net . Http ;
12+ using System . Threading . Tasks ;
1113using Microsoft . ML . Data ;
1214using Microsoft . ML . TestFrameworkCommon ;
1315
@@ -185,13 +187,13 @@ public static string DownloadImageSet(string imagesDownloadFolder)
185187 string fileName = "flower_photos_tiny_set_for_unit_tests.zip" ;
186188 string url = $ "https://aka.ms/mlnet-resources/datasets/flower_photos_tiny_set_for_unit_test.zip";
187189
188- Download ( url , imagesDownloadFolder , fileName ) ;
190+ Download ( url , imagesDownloadFolder , fileName ) . Wait ( ) ;
189191 UnZip ( Path . Combine ( imagesDownloadFolder , fileName ) , imagesDownloadFolder ) ;
190192
191193 return Path . GetFileNameWithoutExtension ( fileName ) ;
192194 }
193195
194- private static void Download ( string url , string destDir , string destFileName )
196+ private static async Task Download ( string url , string destDir , string destFileName )
195197 {
196198 if ( destFileName == null )
197199 destFileName = Path . GetFileName ( new Uri ( url ) . AbsolutePath ) ; ;
@@ -203,7 +205,16 @@ private static void Download(string url, string destDir, string destFileName)
203205 if ( File . Exists ( relativeFilePath ) )
204206 return ;
205207
206- new WebClient ( ) . DownloadFile ( url , relativeFilePath ) ;
208+ using ( var client = new HttpClient ( ) )
209+ {
210+ var response = await client . GetAsync ( url ) . ConfigureAwait ( false ) ;
211+ var stream = await response . EnsureSuccessStatusCode ( ) . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) ;
212+ var fileInfo = new FileInfo ( relativeFilePath ) ;
213+ using ( var fileStream = fileInfo . OpenWrite ( ) )
214+ {
215+ await stream . CopyToAsync ( fileStream ) . ConfigureAwait ( false ) ;
216+ }
217+ }
207218 return ;
208219 }
209220
0 commit comments