Skip to content

Commit

Permalink
Merge pull request #559 from adamhathcock/net5
Browse files Browse the repository at this point in the history
Use Net5, NetCoreApp3.1, NetStandard2.1, NetStandard2.0 only
  • Loading branch information
adamhathcock committed Jan 9, 2021
2 parents faf1a9f + 7edc437 commit bdc57d3
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnetcore.yml
Expand Up @@ -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:
Expand Down
26 changes: 13 additions & 13 deletions build/Program.cs
Expand Up @@ -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")
Expand All @@ -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<string> GetFiles(string d)
{
return Glob.Files(".", d);
}
Target(Test, DependsOn(Build), ForEach("net5.0"),
framework =>
{
IEnumerable<string> 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),
() =>
Expand Down
6 changes: 3 additions & 3 deletions build/build.csproj
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bullseye" Version="3.5.0" />
<PackageReference Include="Bullseye" Version="3.6.0" />
<PackageReference Include="Glob" Version="1.1.8" />
<PackageReference Include="SimpleExec" Version="6.3.0" />
<PackageReference Include="SimpleExec" Version="6.4.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion global.json
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.1.403"
"version": "5.0.101"
}
}
8 changes: 4 additions & 4 deletions src/SharpCompress/Algorithms/Alder32.cs
Expand Up @@ -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
Expand All @@ -22,7 +22,7 @@ internal static class Adler32
/// </summary>
public const uint SeedValue = 1U;

#if NETCOREAPP3_1
#if !NETSTANDARD2_0 && !NETSTANDARD2_1
private const int MinBufferSize = 64;
#endif

Expand Down Expand Up @@ -56,7 +56,7 @@ public static uint Calculate(uint adler, ReadOnlySpan<byte> buffer)
return SeedValue;
}

#if NETCOREAPP3_1
#if !NETSTANDARD2_0 && !NETSTANDARD2_1
if (Sse3.IsSupported && buffer.Length >= MinBufferSize)
{
return CalculateSse(adler, buffer);
Expand All @@ -69,7 +69,7 @@ public static uint Calculate(uint adler, ReadOnlySpan<byte> 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<byte> buffer)
{
uint s1 = adler & 0xFFFF;
Expand Down
3 changes: 1 addition & 2 deletions src/SharpCompress/Archives/Zip/ZipArchive.cs
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs
Expand Up @@ -49,7 +49,10 @@ internal IEnumerable<ZipHeader> 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)
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Zip/ZipFilePart.cs
Expand Up @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Zip/ZipHeaderFactory.cs
Expand Up @@ -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];
Expand Down
18 changes: 2 additions & 16 deletions src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs
Expand Up @@ -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++;
Expand All @@ -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++;
Expand Down
8 changes: 6 additions & 2 deletions src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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)
{
Expand Down
12 changes: 4 additions & 8 deletions src/SharpCompress/SharpCompress.csproj
Expand Up @@ -6,14 +6,12 @@
<AssemblyVersion>0.26.0</AssemblyVersion>
<FileVersion>0.26.0</FileVersion>
<Authors>Adam Hathcock</Authors>
<TargetFrameworks Condition="'$(LibraryFrameworks)'==''">netstandard2.0;netstandard2.1;netcoreapp3.1;net461</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0;netstandard2.1;netcoreapp3.1;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<AssemblyName>SharpCompress</AssemblyName>
<AssemblyOriginatorKeyFile>../../SharpCompress.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>SharpCompress</PackageId>
<PackageTags>rar;unrar;zip;unzip;bzip2;gzip;tar;7zip;lzip;xz</PackageTags>
<PackageProjectUrl>https://github.com/adamhathcock/sharpcompress</PackageProjectUrl>
Expand All @@ -31,14 +29,12 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net5.0' ">
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
</ItemGroup>


<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.1' ">
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net46' ">
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions tests/SharpCompress.Test/SharpCompress.Test.csproj
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
<AssemblyName>SharpCompress.Test</AssemblyName>
<AssemblyOriginatorKeyFile>../../SharpCompress.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand All @@ -12,7 +12,7 @@
<ProjectReference Include="..\..\src\SharpCompress\SharpCompress.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit bdc57d3

Please sign in to comment.