Skip to content

Commit f6c88cf

Browse files
committed
Refactor utils in converter tests
1 parent ae0e788 commit f6c88cf

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

YoutubeExplode.Converter.Tests/Utils/Extensions/FileExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23

34
namespace YoutubeExplode.Converter.Tests.Utils.Extensions;
45

56
internal static class FileExtensions
67
{
78
extension(File)
89
{
9-
public static bool ContainsBytes(string filePath, byte[] data)
10+
public static bool ContainsBytes(string filePath, ReadOnlySpan<byte> data)
1011
{
1112
using var stream = File.OpenRead(filePath);
1213
using var reader = new BinaryReader(stream);
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.IO;
22
using System.Net.Http;
3+
using System.Threading;
34
using System.Threading.Tasks;
45

56
namespace YoutubeExplode.Converter.Tests.Utils.Extensions;
@@ -8,15 +9,24 @@ internal static class HttpExtensions
89
{
910
extension(HttpClient http)
1011
{
11-
public async Task DownloadAsync(string url, string filePath)
12+
public async Task DownloadAsync(
13+
string url,
14+
string filePath,
15+
CancellationToken cancellationToken = default
16+
)
1217
{
13-
using var response = await http.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
18+
using var response = await http.GetAsync(
19+
url,
20+
HttpCompletionOption.ResponseHeadersRead,
21+
cancellationToken
22+
);
23+
1424
response.EnsureSuccessStatusCode();
1525

16-
await using var source = await response.Content.ReadAsStreamAsync();
26+
await using var source = await response.Content.ReadAsStreamAsync(cancellationToken);
1727
await using var destination = File.Create(filePath);
1828

19-
await source.CopyToAsync(destination);
29+
await source.CopyToAsync(destination, cancellationToken);
2030
}
2131
}
2232
}

0 commit comments

Comments
 (0)