Skip to content

Commit

Permalink
Added DownloadFile() method (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Dec 2, 2023
1 parent eb76f94 commit 121b404
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions PeyrSharp.Core/Internet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

using PeyrSharp.Enums;
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

Expand Down Expand Up @@ -92,6 +93,21 @@ public static async Task<bool> IsAvailableAsync()
}
}

public static async Task<bool> DownloadFile(string link, string path)
{
try
{
using HttpClient client = new();
byte[] data = await client.GetByteArrayAsync(link);
await File.WriteAllBytesAsync(path, data);
return true;
}
catch
{
return false;
}
}

/// <summary>
/// Gets the kind of the status code.
/// </summary>
Expand Down

0 comments on commit 121b404

Please sign in to comment.