From 97b0f3ae909278c2473b2bd5656d984b05b3ba45 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 21 Nov 2026 17:23:49 +1100 Subject: [PATCH] Return Task from ZipArchiveEntry.OpenAsync(FileAccess) The polyfill returned ValueTask, but the .NET 11 GA API returns Task. Match the BCL signature, which also removes the need for the FeatureValueTask gate. The test now types the result as Task so a future drift fails to compile. --- api_list.include.md | 2 +- readme.md | 2 +- src/Consume/Consume.cs | 2 -- src/Polyfill/Polyfill_Compression.cs | 6 ++---- src/Split/net10.0/Polyfill_Compression.cs | 6 ++---- src/Split/net461/Polyfill_Compression.cs | 6 ++---- src/Split/net462/Polyfill_Compression.cs | 6 ++---- src/Split/net47/Polyfill_Compression.cs | 6 ++---- src/Split/net471/Polyfill_Compression.cs | 6 ++---- src/Split/net472/Polyfill_Compression.cs | 6 ++---- src/Split/net48/Polyfill_Compression.cs | 6 ++---- src/Split/net481/Polyfill_Compression.cs | 6 ++---- src/Split/net5.0/Polyfill_Compression.cs | 6 ++---- src/Split/net6.0/Polyfill_Compression.cs | 6 ++---- src/Split/net7.0/Polyfill_Compression.cs | 6 ++---- src/Split/net8.0/Polyfill_Compression.cs | 6 ++---- src/Split/net9.0/Polyfill_Compression.cs | 6 ++---- src/Split/netcoreapp2.0/Polyfill_Compression.cs | 6 ++---- src/Split/netcoreapp2.1/Polyfill_Compression.cs | 6 ++---- src/Split/netcoreapp2.2/Polyfill_Compression.cs | 6 ++---- src/Split/netcoreapp3.0/Polyfill_Compression.cs | 6 ++---- src/Split/netcoreapp3.1/Polyfill_Compression.cs | 6 ++---- src/Split/netstandard2.0/Polyfill_Compression.cs | 6 ++---- src/Split/netstandard2.1/Polyfill_Compression.cs | 6 ++---- src/Split/uap10.0/Polyfill_Compression.cs | 6 ++---- src/Tests/PolyfillTests_Compression.cs | 6 +++--- 26 files changed, 49 insertions(+), 95 deletions(-) diff --git a/api_list.include.md b/api_list.include.md index 303c2444b..bd5127d0a 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -1680,7 +1680,7 @@ * `Task ExtractToFileAsync(string, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfileextensions.extracttofileasync?view=net-11.0#system-io-compression-zipfileextensions-extracttofileasync(system-io-compression-ziparchiveentry-system-string-system-threading-cancellationtoken)) * `Stream Open(FileAccess)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.open?view=net-11.0) * `Task OpenAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.openasync?view=net-11.0#system-io-compression-ziparchiveentry-openasync(system-threading-cancellationtoken)) - * `ValueTask OpenAsync(FileAccess, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.openasync?view=net-11.0#system-io-compression-ziparchiveentry-openasync(system-io-fileaccess-system-threading-cancellationtoken)) + * `Task OpenAsync(FileAccess, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.openasync?view=net-11.0#system-io-compression-ziparchiveentry-openasync(system-io-fileaccess-system-threading-cancellationtoken)) * `int ExternalAttributes` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.externalattributes?view=net-11.0) diff --git a/readme.md b/readme.md index 256f15cba..5b337e5b1 100644 --- a/readme.md +++ b/readme.md @@ -2393,7 +2393,7 @@ The class `Polyfill` includes the following extension methods: * `Task ExtractToFileAsync(string, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zipfileextensions.extracttofileasync?view=net-11.0#system-io-compression-zipfileextensions-extracttofileasync(system-io-compression-ziparchiveentry-system-string-system-threading-cancellationtoken)) * `Stream Open(FileAccess)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.open?view=net-11.0) * `Task OpenAsync(CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.openasync?view=net-11.0#system-io-compression-ziparchiveentry-openasync(system-threading-cancellationtoken)) - * `ValueTask OpenAsync(FileAccess, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.openasync?view=net-11.0#system-io-compression-ziparchiveentry-openasync(system-io-fileaccess-system-threading-cancellationtoken)) + * `Task OpenAsync(FileAccess, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.openasync?view=net-11.0#system-io-compression-ziparchiveentry-openasync(system-io-fileaccess-system-threading-cancellationtoken)) * `int ExternalAttributes` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.externalattributes?view=net-11.0) diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index c64f3da5c..cdcb0d4a5 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -2298,9 +2298,7 @@ void XCData_Methods(XCData cdata) => void ZipArchiveEntry_Methods(ZipArchive zip, ZipArchiveEntry entry) { entry.Open(FileAccess.Read); -#if FeatureValueTask entry.OpenAsync(FileAccess.Read); -#endif entry.OpenAsync(); zip.CreateEntryFromFile("file.txt", "entry.txt"); zip.CreateEntryFromFile("file.txt", "entry.txt", CompressionLevel.Optimal); diff --git a/src/Polyfill/Polyfill_Compression.cs b/src/Polyfill/Polyfill_Compression.cs index 4c2cedbd5..7d6c8652c 100644 --- a/src/Polyfill/Polyfill_Compression.cs +++ b/src/Polyfill/Polyfill_Compression.cs @@ -92,18 +92,16 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchiveentry.openasync?view=net-11.0#system-io-compression-ziparchiveentry-openasync(system-io-fileaccess-system-threading-cancellationtoken) - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } #endif -#endif #if !NETSTANDARD2_1_OR_GREATER && !NETCOREAPP2_0_OR_GREATER diff --git a/src/Split/net10.0/Polyfill_Compression.cs b/src/Split/net10.0/Polyfill_Compression.cs index 70ca51710..3a42a56e2 100644 --- a/src/Split/net10.0/Polyfill_Compression.cs +++ b/src/Split/net10.0/Polyfill_Compression.cs @@ -14,15 +14,13 @@ static partial class Polyfill /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/net461/Polyfill_Compression.cs b/src/Split/net461/Polyfill_Compression.cs index 906bd662d..1b6133a85 100644 --- a/src/Split/net461/Polyfill_Compression.cs +++ b/src/Split/net461/Polyfill_Compression.cs @@ -71,16 +71,14 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif /// /// Extracts all the files in the zip archive to a directory on the file system. /// diff --git a/src/Split/net462/Polyfill_Compression.cs b/src/Split/net462/Polyfill_Compression.cs index 906bd662d..1b6133a85 100644 --- a/src/Split/net462/Polyfill_Compression.cs +++ b/src/Split/net462/Polyfill_Compression.cs @@ -71,16 +71,14 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif /// /// Extracts all the files in the zip archive to a directory on the file system. /// diff --git a/src/Split/net47/Polyfill_Compression.cs b/src/Split/net47/Polyfill_Compression.cs index 906bd662d..1b6133a85 100644 --- a/src/Split/net47/Polyfill_Compression.cs +++ b/src/Split/net47/Polyfill_Compression.cs @@ -71,16 +71,14 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif /// /// Extracts all the files in the zip archive to a directory on the file system. /// diff --git a/src/Split/net471/Polyfill_Compression.cs b/src/Split/net471/Polyfill_Compression.cs index 906bd662d..1b6133a85 100644 --- a/src/Split/net471/Polyfill_Compression.cs +++ b/src/Split/net471/Polyfill_Compression.cs @@ -71,16 +71,14 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif /// /// Extracts all the files in the zip archive to a directory on the file system. /// diff --git a/src/Split/net472/Polyfill_Compression.cs b/src/Split/net472/Polyfill_Compression.cs index 906bd662d..1b6133a85 100644 --- a/src/Split/net472/Polyfill_Compression.cs +++ b/src/Split/net472/Polyfill_Compression.cs @@ -71,16 +71,14 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif /// /// Extracts all the files in the zip archive to a directory on the file system. /// diff --git a/src/Split/net48/Polyfill_Compression.cs b/src/Split/net48/Polyfill_Compression.cs index 906bd662d..1b6133a85 100644 --- a/src/Split/net48/Polyfill_Compression.cs +++ b/src/Split/net48/Polyfill_Compression.cs @@ -71,16 +71,14 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif /// /// Extracts all the files in the zip archive to a directory on the file system. /// diff --git a/src/Split/net481/Polyfill_Compression.cs b/src/Split/net481/Polyfill_Compression.cs index 906bd662d..1b6133a85 100644 --- a/src/Split/net481/Polyfill_Compression.cs +++ b/src/Split/net481/Polyfill_Compression.cs @@ -71,16 +71,14 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif /// /// Extracts all the files in the zip archive to a directory on the file system. /// diff --git a/src/Split/net5.0/Polyfill_Compression.cs b/src/Split/net5.0/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/net5.0/Polyfill_Compression.cs +++ b/src/Split/net5.0/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/net6.0/Polyfill_Compression.cs b/src/Split/net6.0/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/net6.0/Polyfill_Compression.cs +++ b/src/Split/net6.0/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/net7.0/Polyfill_Compression.cs b/src/Split/net7.0/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/net7.0/Polyfill_Compression.cs +++ b/src/Split/net7.0/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/net8.0/Polyfill_Compression.cs b/src/Split/net8.0/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/net8.0/Polyfill_Compression.cs +++ b/src/Split/net8.0/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/net9.0/Polyfill_Compression.cs b/src/Split/net9.0/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/net9.0/Polyfill_Compression.cs +++ b/src/Split/net9.0/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/netcoreapp2.0/Polyfill_Compression.cs b/src/Split/netcoreapp2.0/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/netcoreapp2.0/Polyfill_Compression.cs +++ b/src/Split/netcoreapp2.0/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/netcoreapp2.1/Polyfill_Compression.cs b/src/Split/netcoreapp2.1/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/netcoreapp2.1/Polyfill_Compression.cs +++ b/src/Split/netcoreapp2.1/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/netcoreapp2.2/Polyfill_Compression.cs b/src/Split/netcoreapp2.2/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/netcoreapp2.2/Polyfill_Compression.cs +++ b/src/Split/netcoreapp2.2/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/netcoreapp3.0/Polyfill_Compression.cs b/src/Split/netcoreapp3.0/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/netcoreapp3.0/Polyfill_Compression.cs +++ b/src/Split/netcoreapp3.0/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/netcoreapp3.1/Polyfill_Compression.cs b/src/Split/netcoreapp3.1/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/netcoreapp3.1/Polyfill_Compression.cs +++ b/src/Split/netcoreapp3.1/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/netstandard2.0/Polyfill_Compression.cs b/src/Split/netstandard2.0/Polyfill_Compression.cs index 906bd662d..1b6133a85 100644 --- a/src/Split/netstandard2.0/Polyfill_Compression.cs +++ b/src/Split/netstandard2.0/Polyfill_Compression.cs @@ -71,16 +71,14 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif /// /// Extracts all the files in the zip archive to a directory on the file system. /// diff --git a/src/Split/netstandard2.1/Polyfill_Compression.cs b/src/Split/netstandard2.1/Polyfill_Compression.cs index 5f1c8b455..208c619d0 100644 --- a/src/Split/netstandard2.1/Polyfill_Compression.cs +++ b/src/Split/netstandard2.1/Polyfill_Compression.cs @@ -71,15 +71,13 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif } #endif diff --git a/src/Split/uap10.0/Polyfill_Compression.cs b/src/Split/uap10.0/Polyfill_Compression.cs index 906bd662d..1b6133a85 100644 --- a/src/Split/uap10.0/Polyfill_Compression.cs +++ b/src/Split/uap10.0/Polyfill_Compression.cs @@ -71,16 +71,14 @@ public static Task ExtractToFileAsync(this ZipArchiveEntry source, string destin /// public static Stream Open(this ZipArchiveEntry target, FileAccess access) => target.Open(); -#if FeatureValueTask /// /// Asynchronously opens the entry from the zip archive with the specified access mode. /// - public static ValueTask OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) + public static Task OpenAsync(this ZipArchiveEntry target, FileAccess access, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); - return new ValueTask(target.Open()); + return Task.FromResult(target.Open()); } -#endif /// /// Extracts all the files in the zip archive to a directory on the file system. /// diff --git a/src/Tests/PolyfillTests_Compression.cs b/src/Tests/PolyfillTests_Compression.cs index 441a856ff..a69b039b8 100644 --- a/src/Tests/PolyfillTests_Compression.cs +++ b/src/Tests/PolyfillTests_Compression.cs @@ -95,7 +95,6 @@ public async Task ZipArchiveEntry_Open_WithFileAccess() await Assert.That(result).IsEqualTo("content"); } -#if FeatureValueTask [Test] public async Task ZipArchiveEntry_OpenAsync_WithFileAccess() { @@ -114,12 +113,13 @@ public async Task ZipArchiveEntry_OpenAsync_WithFileAccess() using var readArchive = new ZipArchive(memStream, ZipArchiveMode.Read); var readEntry = readArchive.Entries[0]; - using var readStream = await readEntry.OpenAsync(FileAccess.Read); + // typed as Task so the test fails to compile if the polyfill drifts from the BCL return type + Task openTask = readEntry.OpenAsync(FileAccess.Read); + using var readStream = await openTask; using var reader = new StreamReader(readStream); var result = await reader.ReadToEndAsync(); await Assert.That(result).IsEqualTo("content"); } -#endif [Test] public async Task ExtractToDirectory_Extracts_All_Entries()