Skip to content

Commit

Permalink
Revert async method.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed May 23, 2024
1 parent b29a440 commit 2f0611d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageProjectUrl>https://github.com/squidex/squidex</PackageProjectUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>6.8.4</Version>
<Version>6.8.5</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
4 changes: 1 addition & 3 deletions assets/Squidex.Assets.Tests/TempAssetFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public async Task Should_construct()
[Fact]
public async Task Should_construct_from_other_file()
{
var source =
new DelegateAssetFile("fileName", "file/type", 1024, ct =>
new ValueTask<Stream>(new MemoryStream()));
var source = new DelegateAssetFile("fileName", "file/type", 1024, () => new MemoryStream());

await using (var result = TempAssetFile.Create(source))
{
Expand Down
5 changes: 2 additions & 3 deletions assets/Squidex.Assets.TusAdapter/AssetTusFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ public ValueTask DisposeAsync()
return stream.DisposeAsync();
}

public ValueTask<Stream> OpenReadAsync(
CancellationToken ct = default)
public Stream OpenRead()
{
return new ValueTask<Stream>(new NonDisposingStream(stream));
return new NonDisposingStream(stream);
}

public Task<Stream> GetContentAsync(
Expand Down
15 changes: 5 additions & 10 deletions assets/Squidex.Assets/DelegateAssetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@ namespace Squidex.Assets;

public class DelegateAssetFile : IAssetFile
{
private readonly Func<CancellationToken, ValueTask<Stream>> openStream;
private readonly Func<Stream> openStream;

public string FileName { get; }

public string MimeType { get; }

public long FileSize { get; }

public DelegateAssetFile(string fileName, string mimeType, long fileSize, Func<Stream> openStream)
: this(fileName, mimeType, fileSize, _ => new ValueTask<Stream>(openStream()))
{
}

public DelegateAssetFile(string fileName, string mimeType, long fileSize,
Func<CancellationToken, ValueTask<Stream>> openStream)
Func<Stream> openStream)
{
ArgumentException.ThrowIfNullOrWhiteSpace(fileName);
ArgumentException.ThrowIfNullOrWhiteSpace(mimeType);
Expand All @@ -36,14 +31,14 @@ public DelegateAssetFile(string fileName, string mimeType, long fileSize,
this.openStream = openStream;
}

public ValueTask<Stream> OpenReadAsync(
CancellationToken ct = default)
public Stream OpenRead()
{
return openStream(ct);
return openStream();
}

public ValueTask DisposeAsync()
{
GC.SuppressFinalize(this);
return default;
}
}
3 changes: 1 addition & 2 deletions assets/Squidex.Assets/IAssetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public interface IAssetFile : IAsyncDisposable

string MimeType { get; }

ValueTask<Stream> OpenReadAsync(
CancellationToken ct = default);
Stream OpenRead();
}
2 changes: 1 addition & 1 deletion assets/TusTestServer/Controller/TusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<IActionResult> Tus()
return result;
}

await using var fileStream = await file.OpenReadAsync(HttpContext.RequestAborted);
await using var fileStream = file.OpenRead();

var name = file.FileName;

Expand Down
2 changes: 1 addition & 1 deletion assets/TusTestServer/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void UseMyTus<T>(this WebApplication app, string path) where T : I
{
var file = (IAssetFile)(await eventContext.GetFileAsync());

await using var fileStream = await file.OpenReadAsync(eventContext.CancellationToken);
await using var fileStream = file.OpenRead();

var name = file.FileName;

Expand Down

0 comments on commit 2f0611d

Please sign in to comment.