From 1c03587cd887500f65af601497e1930a8a317fca Mon Sep 17 00:00:00 2001 From: Kerry Cao Date: Tue, 28 Jan 2025 21:42:12 -0500 Subject: [PATCH] obsolete webclient replaced with httpclient --- FFMpegCore.Extensions.Downloader/FFMpegDownloader.cs | 6 +++--- .../Services/FFbinariesService.cs | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/FFMpegCore.Extensions.Downloader/FFMpegDownloader.cs b/FFMpegCore.Extensions.Downloader/FFMpegDownloader.cs index 87c6fd9..0def62b 100644 --- a/FFMpegCore.Extensions.Downloader/FFMpegDownloader.cs +++ b/FFMpegCore.Extensions.Downloader/FFMpegDownloader.cs @@ -30,21 +30,21 @@ public class FFMpegDownloader // download ffmpeg if selected if (binaries.HasFlag(FFMpegBinaries.FFMpeg) && downloadInfo.FFMpeg is not null) { - var zipStream = FFbinariesService.DownloadFileAsSteam(new Uri(downloadInfo.FFMpeg)); + await using var zipStream = await FFbinariesService.DownloadFileAsSteam(new Uri(downloadInfo.FFMpeg)); successList.AddRange(FFbinariesService.ExtractZipAndSave(zipStream)); } // download ffprobe if selected if (binaries.HasFlag(FFMpegBinaries.FFProbe) && downloadInfo.FFProbe is not null) { - var zipStream = FFbinariesService.DownloadFileAsSteam(new Uri(downloadInfo.FFProbe)); + await using var zipStream = await FFbinariesService.DownloadFileAsSteam(new Uri(downloadInfo.FFProbe)); successList.AddRange(FFbinariesService.ExtractZipAndSave(zipStream)); } // download ffplay if selected if (binaries.HasFlag(FFMpegBinaries.FFPlay) && downloadInfo.FFPlay is not null) { - var zipStream = FFbinariesService.DownloadFileAsSteam(new Uri(downloadInfo.FFPlay)); + await using var zipStream = await FFbinariesService.DownloadFileAsSteam(new Uri(downloadInfo.FFPlay)); successList.AddRange(FFbinariesService.ExtractZipAndSave(zipStream)); } diff --git a/FFMpegCore.Extensions.Downloader/Services/FFbinariesService.cs b/FFMpegCore.Extensions.Downloader/Services/FFbinariesService.cs index 2a6c616..dd35513 100644 --- a/FFMpegCore.Extensions.Downloader/Services/FFbinariesService.cs +++ b/FFMpegCore.Extensions.Downloader/Services/FFbinariesService.cs @@ -43,13 +43,10 @@ internal class FFbinariesService /// /// uri of the file /// - internal static MemoryStream DownloadFileAsSteam(Uri address) + internal static async Task DownloadFileAsSteam(Uri address) { - var client = new WebClient(); - var fileStream = new MemoryStream(client.DownloadData(address)); - fileStream.Position = 0; - - return fileStream; + var client = new HttpClient(); + return await client.GetStreamAsync(address); } ///