diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 531454208..d36c81db9 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.403 + dotnet-version: 5.0.101 - run: dotnet run -p build/build.csproj - uses: actions/upload-artifact@v2 with: diff --git a/build/Program.cs b/build/Program.cs index 7c97ed0fe..81ac2a91e 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -46,7 +46,7 @@ void RemoveDirectory(string d) Run("dotnet", "format --check"); }); - Target(Build, DependsOn(Format), ForEach("net46", "netstandard2.0", "netstandard2.1"), + Target(Build, DependsOn(Format), framework => { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && framework == "net46") @@ -56,19 +56,19 @@ void RemoveDirectory(string d) Run("dotnet", "build src/SharpCompress/SharpCompress.csproj -c Release"); }); - Target(Test, DependsOn(Build), ForEach("netcoreapp3.1"), - framework => - { - IEnumerable GetFiles(string d) - { - return Glob.Files(".", d); - } + Target(Test, DependsOn(Build), ForEach("net5.0"), + framework => + { + IEnumerable GetFiles(string d) + { + return Glob.Files(".", d); + } - foreach (var file in GetFiles("**/*.Test.csproj")) - { - Run("dotnet", $"test {file} -c Release -f {framework}"); - } - }); + foreach (var file in GetFiles("**/*.Test.csproj")) + { + Run("dotnet", $"test {file} -c Release -f {framework}"); + } + }); Target(Publish, DependsOn(Test), () => diff --git a/build/build.csproj b/build/build.csproj index 2600bddad..635e5b012 100644 --- a/build/build.csproj +++ b/build/build.csproj @@ -2,13 +2,13 @@ Exe - netcoreapp3.1 + net5.0 - + - + diff --git a/global.json b/global.json index 9731311d0..fbb332028 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.1.403" + "version": "5.0.101" } } \ No newline at end of file diff --git a/src/SharpCompress/Algorithms/Alder32.cs b/src/SharpCompress/Algorithms/Alder32.cs index d0b3279fd..06dfed524 100644 --- a/src/SharpCompress/Algorithms/Alder32.cs +++ b/src/SharpCompress/Algorithms/Alder32.cs @@ -4,7 +4,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#if NETCOREAPP3_1 +#if !NETSTANDARD2_0 && !NETSTANDARD2_1 using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; #endif @@ -22,7 +22,7 @@ internal static class Adler32 /// public const uint SeedValue = 1U; -#if NETCOREAPP3_1 +#if !NETSTANDARD2_0 && !NETSTANDARD2_1 private const int MinBufferSize = 64; #endif @@ -56,7 +56,7 @@ public static uint Calculate(uint adler, ReadOnlySpan buffer) return SeedValue; } -#if NETCOREAPP3_1 +#if !NETSTANDARD2_0 && !NETSTANDARD2_1 if (Sse3.IsSupported && buffer.Length >= MinBufferSize) { return CalculateSse(adler, buffer); @@ -69,7 +69,7 @@ public static uint Calculate(uint adler, ReadOnlySpan buffer) } // Based on https://github.com/chromium/chromium/blob/master/third_party/zlib/adler32_simd.c -#if NETCOREAPP3_1 +#if !NETSTANDARD2_0 && !NETSTANDARD2_1 private static unsafe uint CalculateSse(uint adler, ReadOnlySpan buffer) { uint s1 = adler & 0xFFFF; diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs index 9994ccdd1..58d94ee0f 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs @@ -80,8 +80,7 @@ public static bool IsZipFile(Stream stream, string? password = null) StreamingZipHeaderFactory headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding()); try { - ZipHeader header = - headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split); + ZipHeader? header = headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split); if (header is null) { return false; diff --git a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs index 59953e534..3c273e326 100644 --- a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs @@ -49,7 +49,10 @@ internal IEnumerable ReadStreamHeader(Stream stream) _lastEntryHeader = null; uint headerBytes = reader.ReadUInt32(); header = ReadHeader(headerBytes, reader); - if (header is null) { yield break; } + if (header is null) + { + yield break; + } //entry could be zero bytes so we need to know that. if (header.ZipHeaderType == ZipHeaderType.LocalEntry) diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs index 6176bccf4..23fbaf24b 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs @@ -99,7 +99,7 @@ protected Stream CreateDecompressionStream(Stream stream, ZipCompressionMethod m } case ZipCompressionMethod.WinzipAes: { - ExtraData data = Header.Extra.Where(x => x.Type == ExtraDataType.WinZipAes).SingleOrDefault(); + ExtraData? data = Header.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); if (data is null) { throw new InvalidFormatException("No Winzip AES extra data found."); diff --git a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs index 3e67e5af1..fac558d22 100644 --- a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs @@ -129,7 +129,7 @@ private void LoadHeader(ZipFileEntry entryHeader, Stream stream) if (entryHeader.CompressionMethod == ZipCompressionMethod.WinzipAes) { - ExtraData data = entryHeader.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); + ExtraData? data = entryHeader.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); if (data != null) { var keySize = (WinzipAesKeySize)data.DataBytes[4]; diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs index a0e9705a0..b86695bdf 100644 --- a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs +++ b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs @@ -604,14 +604,7 @@ private void BsFinishedWithStream() while (bsLive > 0) { int ch = (bsBuff >> 24); - try - { - bsStream.WriteByte((byte)ch); // write 8-bit - } - catch (IOException e) - { - throw e; - } + bsStream.WriteByte((byte)ch); // write 8-bit bsBuff <<= 8; bsLive -= 8; bytesOut++; @@ -623,14 +616,7 @@ private void BsW(int n, int v) while (bsLive >= 8) { int ch = (bsBuff >> 24); - try - { - bsStream.WriteByte((byte)ch); // write 8-bit - } - catch (IOException e) - { - throw e; - } + bsStream.WriteByte((byte)ch); // write 8-bit bsBuff <<= 8; bsLive -= 8; bytesOut++; diff --git a/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs b/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs index 7c2a81631..e59363dfe 100644 --- a/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs @@ -31,7 +31,11 @@ public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long Init(info, out int numCyclesPower, out byte[] salt, out byte[] seed); byte[] password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword()); - byte[] key = InitKey(numCyclesPower, salt, password); + byte[]? key = InitKey(numCyclesPower, salt, password); + if (key == null) + { + throw new InvalidOperationException("Initialized with null key"); + } using (var aes = Aes.Create()) { @@ -177,7 +181,7 @@ private void Init(byte[] info, out int numCyclesPower, out byte[] salt, out byte } } - private byte[] InitKey(int mNumCyclesPower, byte[] salt, byte[] pass) + private byte[]? InitKey(int mNumCyclesPower, byte[] salt, byte[] pass) { if (mNumCyclesPower == 0x3F) { diff --git a/src/SharpCompress/SharpCompress.csproj b/src/SharpCompress/SharpCompress.csproj index de803800e..b4ced089b 100644 --- a/src/SharpCompress/SharpCompress.csproj +++ b/src/SharpCompress/SharpCompress.csproj @@ -6,14 +6,12 @@ 0.26.0 0.26.0 Adam Hathcock - netstandard2.0;netstandard2.1;netcoreapp3.1;net461 - netstandard2.0;netstandard2.1;netcoreapp3.1; + netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0 true false SharpCompress ../../SharpCompress.snk true - true SharpCompress rar;unrar;zip;unzip;bzip2;gzip;tar;7zip;lzip;xz https://github.com/adamhathcock/sharpcompress @@ -31,14 +29,12 @@ + + + - - - - - diff --git a/tests/SharpCompress.Test/SharpCompress.Test.csproj b/tests/SharpCompress.Test/SharpCompress.Test.csproj index 0c3d5d6f3..fbb420d63 100644 --- a/tests/SharpCompress.Test/SharpCompress.Test.csproj +++ b/tests/SharpCompress.Test/SharpCompress.Test.csproj @@ -1,6 +1,6 @@  - net461;netcoreapp3.1 + net5.0 SharpCompress.Test ../../SharpCompress.snk true @@ -12,7 +12,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive