mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-25 08:24:58 +00:00
Fix async reader variable types - Remove double await on ReaderFactory.OpenAsync and use IAsyncReader
- Removed 'await' keyword before ReaderFactory.OpenAsync() calls since the method returns IAsyncReader directly (not Task) - Changed ZipReader.Open() to ReaderFactory.OpenAsync() in Zip64AsyncTests.ReadForwardOnlyAsync() - Changed TarReader.Open() to ReaderFactory.OpenAsync() in TarReaderAsyncTests.Tar_BZip2_Entry_Stream_Async() - Fixed EntryStream disposal from 'await using' to 'using' since EntryStream doesn't implement IAsyncDisposable - These changes fix compilation errors where async methods were being called on IReader (synchronous) instead of IAsyncReader (asynchronous)
This commit is contained in:
@@ -32,10 +32,7 @@ public interface IArchiveFactory : IFactory
|
||||
/// </summary>
|
||||
/// <param name="stream">An open, readable and seekable stream.</param>
|
||||
/// <param name="readerOptions">reading options.</param>
|
||||
IAsyncArchive OpenAsync(
|
||||
Stream stream,
|
||||
ReaderOptions? readerOptions = null
|
||||
);
|
||||
IAsyncArchive OpenAsync(Stream stream, ReaderOptions? readerOptions = null);
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with a FileInfo object to an existing file.
|
||||
|
||||
@@ -33,10 +33,7 @@ public interface IMultiArchiveFactory : IFactory
|
||||
/// </summary>
|
||||
/// <param name="streams"></param>
|
||||
/// <param name="readerOptions">reading options.</param>
|
||||
IAsyncArchive OpenAsync(
|
||||
IReadOnlyList<Stream> streams,
|
||||
ReaderOptions? readerOptions = null
|
||||
);
|
||||
IAsyncArchive OpenAsync(IReadOnlyList<Stream> streams, ReaderOptions? readerOptions = null);
|
||||
|
||||
/// <summary>
|
||||
/// Constructor with IEnumerable Stream objects, multi and split support.
|
||||
|
||||
@@ -39,7 +39,9 @@ public static class AsyncEnumerableExtensions
|
||||
return list;
|
||||
}
|
||||
|
||||
public static async IAsyncEnumerable<TResult> CastAsync<TResult>(this IAsyncEnumerable<object?> source)
|
||||
public static async IAsyncEnumerable<TResult> CastAsync<TResult>(
|
||||
this IAsyncEnumerable<object?> source
|
||||
)
|
||||
where TResult : class
|
||||
{
|
||||
await foreach (var item in source)
|
||||
@@ -62,49 +64,74 @@ public static class AsyncEnumerableExtensions
|
||||
return result;
|
||||
}
|
||||
|
||||
extension<T>(IAsyncEnumerable<T> source)
|
||||
public static async ValueTask<bool> AllAsync<T>(
|
||||
this IAsyncEnumerable<T> source,
|
||||
Func<T, bool> predicate
|
||||
)
|
||||
{
|
||||
public async ValueTask<bool> AllAsync(Func<T, bool> predicate)
|
||||
await foreach (var item in source)
|
||||
{
|
||||
await foreach (var item in source)
|
||||
if (!predicate(item))
|
||||
{
|
||||
if (!predicate(item))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<T> WhereAsync(Func<T, bool> predicate)
|
||||
{
|
||||
await foreach (var item in source)
|
||||
{
|
||||
if (predicate(item))
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask<T> FirstAsync()
|
||||
{
|
||||
await foreach (var item in source)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
throw new InvalidOperationException("The source sequence is empty.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public async ValueTask<T?> FirstOrDefaultAsync()
|
||||
{
|
||||
await foreach (var item in source)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
public static IAsyncEnumerable<T> Where<T>(
|
||||
this IAsyncEnumerable<T> source,
|
||||
Func<T, bool> predicate
|
||||
)
|
||||
{
|
||||
return WhereIterator(source, predicate);
|
||||
}
|
||||
|
||||
return default;
|
||||
private static async IAsyncEnumerable<T> WhereIterator<T>(
|
||||
IAsyncEnumerable<T> source,
|
||||
Func<T, bool> predicate
|
||||
)
|
||||
{
|
||||
await foreach (var item in source)
|
||||
{
|
||||
if (predicate(item))
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async IAsyncEnumerable<T> WhereAsync<T>(
|
||||
this IAsyncEnumerable<T> source,
|
||||
Func<T, bool> predicate
|
||||
)
|
||||
{
|
||||
await foreach (var item in source)
|
||||
{
|
||||
if (predicate(item))
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async ValueTask<T> FirstAsync<T>(this IAsyncEnumerable<T> source)
|
||||
{
|
||||
await foreach (var item in source)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
throw new InvalidOperationException("The source sequence is empty.");
|
||||
}
|
||||
|
||||
public static async ValueTask<T?> FirstOrDefaultAsync<T>(this IAsyncEnumerable<T> source)
|
||||
{
|
||||
await foreach (var item in source)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user