diff --git a/src/libraries/System.IO.Compression.Brotli/ref/System.IO.Compression.Brotli.cs b/src/libraries/System.IO.Compression.Brotli/ref/System.IO.Compression.Brotli.cs index b201f053a9d06e..9faa236f84970c 100644 --- a/src/libraries/System.IO.Compression.Brotli/ref/System.IO.Compression.Brotli.cs +++ b/src/libraries/System.IO.Compression.Brotli/ref/System.IO.Compression.Brotli.cs @@ -6,9 +6,10 @@ namespace System.IO.Compression { - public sealed class BrotliCompressionOptions + public sealed partial class BrotliCompressionOptions { - public int Quality { get; set; } + public BrotliCompressionOptions() { } + public int Quality { get { throw null; } set { } } } public partial struct BrotliDecoder : System.IDisposable { diff --git a/src/libraries/System.IO.Compression.ZipFile/tests/ZipArchiveEntry.ExtractToDirectory.cs b/src/libraries/System.IO.Compression.ZipFile/tests/ZipArchiveEntry.ExtractToDirectory.cs deleted file mode 100644 index d4c40f60decdcb..00000000000000 --- a/src/libraries/System.IO.Compression.ZipFile/tests/ZipArchiveEntry.ExtractToDirectory.cs +++ /dev/null @@ -1,115 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using Xunit; -using Microsoft.DotNet.XUnitExtensions; - -namespace System.IO.Compression.Tests -{ - public class ZipArchiveEntry_ExtractToDirectory : ZipFileTestBase - { - public static IEnumerable TestData() - { - yield return new string[] { "AbsoluteNoRelative.zip", "System.IO.IOException" }; - yield return new string[] { "AbsoluteWithRelativeOut.zip", "System.IO.IOException" }; - yield return new string[] { "DotMarkDevicePath.zip", @"System.IO.IOException" }; - yield return new string[] { "QuestionMarkDevicePath.zip", @"System.IO.IOException" }; - yield return new string[] { "RelativeFirst.zip", @"System.IO.IOException" }; - yield return new string[] { "ValidNestedRelative.zip", @"./foo/../sample.txt" }; - yield return new string[] { "NestedDotDevicePath.zip", @"System.IO.IOException" }; - yield return new string[] { "NestedQuestionDevicePath.zip", @"System.IO.IOException" }; - yield return new string[] { "RelativeAtStartAndEnd.zip", @"System.IO.IOException" }; - yield return new string[] { "JustDotdot.zip", @"System.IO.IOException" }; - yield return new string[] { "TrailingDotDot.zip", @"System.IO.IOException" }; - yield return new string[] { "MarkedDotDot.zip", @"System.IO.IOException" }; - yield return new string[] { "JustSlash.zip", @"System.IO.IOException" }; - yield return new string[] { "DotSlashDirectory.zip", @"./sample.txt" }; - yield return new string[] { "DoubleSlash.zip", @"foo//sample.txt" }; - yield return new string[] { "CurrentInsidePath.zip", @"parent/./child" }; - yield return new string[] { "Justdot.zip", @"System.IO.IOException" }; - yield return new string[] { "SlashDotStuff.zip", @"System.IO.IOException" }; - yield return new string[] { "TestNew1.zip", @"s/../stuff" }; - yield return new string[] { "TestNew2.zip", @"System.IO.IOException" }; - yield return new string[] { "TestNew3.zip", @"s/..\t\../j/try" }; - yield return new string[] { "TestNew4.zip", @"System.IO.IOException" }; - yield return new string[] { "TestNew5.zip", @"System.IO.IOException" }; - yield return new string[] { "TestNew6.zip", @"System.IO.IOException" }; - yield return new string[] { "TestNew7.zip", @"t/h/i/s/../../../../script" }; - yield return new string[] { "TestNew8.zip", @"System.IO.IOException" }; - yield return new string[] { "TestNew9.zip", @"System.IO.IOException" }; - yield return new string[] { "TestNew10.zip", @"System.IO.IOException" }; - yield return new string[] { "TestNew11.zip", @"./././././././5" }; - yield return new string[] { "InvalidChar1.zip", "System.ArgumentException" }; - yield return new string[] { "InvalidChar2.zip", @"sample.:xt" }; - yield return new string[] { "InvalidChar3.zip", "System.ArgumentException" }; - yield return new string[] { "EncodedDotDots.zip", "lib/%2E%2E/%2E%2E/%2E%2E/bad.exe" }; - yield return new string[] { "SpacedRelative.zip", "System.IO.DirectoryNotFoundException" }; - } - - [Theory] - [MemberData(nameof(TestData))] - public static void Entry_ExtractToDirectory(string zipFile, string expectedOutPath) - { - using (TempDirectory destinationDirectory = new TempDirectory()) - { - try - { - using (ZipArchive archive = ZipFile.OpenRead(zipFile)) - { - foreach (ZipArchiveEntry entry in archive.Entries) - { - entry.ExtractRelativeToDirectory(destinationDirectory.Path, false); - Assert.True(File.Exists(Path.Combine(destinationDirectory.Path, expectedOutPath))); - } - } - } - catch (Exception e) - { - Assert.Equal(expectedOutPath, e.GetType().ToString()); - } - } - } - - [Theory] - [MemberData(nameof(TestData))] - public static void Archive_ExtractToDirectory(string zipFile, string expectedOutPath) - { - using (TempDirectory destinationDirectory = new TempDirectory()) - { - try - { - ZipFile.ExtractToDirectory(zipFile, destinationDirectory.Path); - Assert.True(File.Exists(Path.Combine(destinationDirectory.Path, expectedOutPath))); - } - catch (Exception e) - { - Assert.Equal(expectedOutPath, e.GetType().ToString()); - } - } - } - - [Fact] - public void ExtractToDirectoryZipArchiveOverwrite() - { - string zipFileName = zfile("normal.zip"); - string folderName = zfolder("normal"); - - using (var tempFolder = new TempDirectory(GetTestFilePath())) - { - using (ZipArchive archive = ZipFile.Open(zipFileName, ZipArchiveMode.Read)) - { - archive.ExtractToDirectory(tempFolder.Path); - Assert.Throws(() => archive.ExtractToDirectory(tempFolder.Path /* default false */)); - Assert.Throws(() => archive.ExtractToDirectory(tempFolder.Path, overwriteFiles: false)); - archive.ExtractToDirectory(tempFolder.Path, overwriteFiles: true); - - DirsEqual(tempFolder.Path, folderName); - } - } - } - } -} diff --git a/src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.ExtractToDirectoryFiltered.cs b/src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.ExtractToDirectoryFiltered.cs deleted file mode 100644 index 0df8cd2b6962d7..00000000000000 --- a/src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.ExtractToDirectoryFiltered.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using Xunit; -using Microsoft.DotNet.XUnitExtensions; -using System.Linq; -namespace System.IO.Compression.Tests -{ - public class ZipFile_ExtractToDirectoryFiltered : ZipFileTestBase - { - [Fact] - public static void ExtractFilteredZip() - { - using (TempDirectory destinationDirectory = new TempDirectory()) - { - ZipFile.ExtractToDirectory("Filter.zip", destinationDirectory.Path, (path) => path.EndsWith(".txt")); - Assert.True(File.Exists(Path.Combine(destinationDirectory.Path, ".txt"))); - Assert.True(File.Exists(Path.Combine(destinationDirectory.Path, ".pkg.txt"))); - Assert.True(File.Exists(Path.Combine(destinationDirectory.Path, ".txt.txt"))); - Assert.True(Directory.EnumerateFileSystemEntries(destinationDirectory.Path).Count() == 3); - } - } - - } -} diff --git a/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs b/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs index ce06edd97ba2af..b0986385eabf16 100644 --- a/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs +++ b/src/libraries/System.IO.Compression/ref/System.IO.Compression.cs @@ -131,10 +131,11 @@ public enum ZipArchiveMode Create = 1, Update = 2, } - public sealed class ZLibCompressionOptions + public sealed partial class ZLibCompressionOptions { - public int CompressionLevel { get; set; } - public ZLibCompressionStrategy CompressionStrategy { get; set; } + public ZLibCompressionOptions() { } + public int CompressionLevel { get { throw null; } set { } } + public System.IO.Compression.ZLibCompressionStrategy CompressionStrategy { get { throw null; } set { } } } public enum ZLibCompressionStrategy { @@ -142,7 +143,7 @@ public enum ZLibCompressionStrategy Filtered = 1, HuffmanOnly = 2, RunLengthEncoding = 3, - Fixed = 4 + Fixed = 4, } public sealed partial class ZLibStream : System.IO.Stream { diff --git a/src/libraries/System.IO.Compression/src/ReferenceAssemblyExclusions.txt b/src/libraries/System.IO.Compression/src/ReferenceAssemblyExclusions.txt new file mode 100644 index 00000000000000..b83910ba046bcd --- /dev/null +++ b/src/libraries/System.IO.Compression/src/ReferenceAssemblyExclusions.txt @@ -0,0 +1,2 @@ +T:System.IO.Compression.ZLibException + diff --git a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj index a744c58082b4c2..1ad16f09e8af6e 100644 --- a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj +++ b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj @@ -4,6 +4,7 @@ $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)-wasi;$(NetCoreAppCurrent) true false + ReferenceAssemblyExclusions.txt diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs index 81445644856a94..67fbbd4ba400d8 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/DeflateStream.cs @@ -406,7 +406,7 @@ public override Task ReadAsync(byte[] buffer, int offset, int count, Cancel return ReadAsyncMemory(new Memory(buffer, offset, count), cancellationToken).AsTask(); } - public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default(CancellationToken)) + public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) { if (GetType() != typeof(DeflateStream)) { @@ -813,7 +813,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati return WriteAsyncMemory(new ReadOnlyMemory(buffer, offset, count), cancellationToken).AsTask(); } - public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken) + public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) { if (GetType() != typeof(DeflateStream)) {