Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/IsExternalInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// This file is required for init-only properties to work on older target frameworks (.NET Framework 4.8, .NET Standard 2.0)
// The IsExternalInit type is used by the compiler for records and init-only properties

#if NETFRAMEWORK || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NETSTANDARD2_1
using System.ComponentModel;

namespace System.Runtime.CompilerServices;
Expand Down
18 changes: 18 additions & 0 deletions src/SharpCompress/Common/MemberNotNullAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Compatibility shim for frameworks that don't expose MemberNotNullAttribute
#if NETSTANDARD2_1 || LEGACY_DOTNET
using System;

namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(
AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor,
AllowMultiple = true
)]
internal sealed class MemberNotNullAttribute : Attribute
{
public MemberNotNullAttribute(string member) { }

public MemberNotNullAttribute(params string[] members) { }
}
}
#endif
4 changes: 2 additions & 2 deletions src/SharpCompress/Common/Rar/CryptKey5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int keyLength
)
{
var passwordBytes = Encoding.UTF8.GetBytes(password);
#if LEGACY_DOTNET
#if LEGACY_DOTNET || NET5_0
using var hmac = new HMACSHA256(passwordBytes);
var block = hmac.ComputeHash(salt);
#else
Expand All @@ -50,7 +50,7 @@ int keyLength
{
for (var i = 1; i < loop[x]; i++)
{
#if LEGACY_DOTNET
#if LEGACY_DOTNET || NET5_0
block = hmac.ComputeHash(block);
#else
block = HMACSHA256.HashData(passwordBytes, block);
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Rar/Headers/MarkHeader.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static async ValueTask<MarkHeader> ReadAsync(
{
if (!leaveStreamOpen)
{
#if LEGACY_DOTNET
#if LEGACY_DOTNET && !NETSTANDARD2_1
stream.Dispose();
#else
await stream.DisposeAsync().ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private async ValueTask WriteUstarAsync(Stream output, CancellationToken cancell
int splitIndex = -1;
for (int i = 0; i < dirSeps.Count; i++)
{
#if NET8_0_OR_GREATER
#if NET5_0_OR_GREATER
int count = ArchiveEncoding
.GetEncoding()
.GetByteCount(fullName.AsSpan(0, dirSeps[i]));
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Tar/Headers/TarHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal void WriteUstar(Stream output)
int splitIndex = -1;
for (int i = 0; i < dirSeps.Count; i++)
{
#if NET8_0_OR_GREATER
#if NET5_0_OR_GREATER
int count = ArchiveEncoding
.GetEncoding()
.GetByteCount(fullName.AsSpan(0, dirSeps[i]));
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Compressors/PPMd/PpmdStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ await instance
}
catch
{
#if LEGACY_DOTNET
#if LEGACY_DOTNET && !NETSTANDARD2_1
instance.Dispose();
#else
await instance.DisposeAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SharpCompress.Compressors.ZStandard;

public partial class CompressionStream : Stream
{
#if !LEGACY_DOTNET
#if !LEGACY_DOTNET || NETSTANDARD2_1
public override async ValueTask DisposeAsync()
#else
public async ValueTask DisposeAsync()
Expand Down Expand Up @@ -95,7 +95,7 @@ await innerStream
);
}

#if !LEGACY_DOTNET
#if !LEGACY_DOTNET || NETSTANDARD2_1

public override Task WriteAsync(
byte[] buffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void FlushInternal(ZSTD_EndDirective directive) =>
public override void Write(byte[] buffer, int offset, int count) =>
Write(new ReadOnlySpan<byte>(buffer, offset, count));

#if !LEGACY_DOTNET
#if !LEGACY_DOTNET || NETSTANDARD2_1
public override void Write(ReadOnlySpan<byte> buffer) =>
WriteInternal(buffer, ZSTD_EndDirective.ZSTD_e_continue);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SharpCompress.Compressors.ZStandard;

public partial class DecompressionStream
{
#if !LEGACY_DOTNET
#if !LEGACY_DOTNET || NETSTANDARD2_1
public override Task<int> ReadAsync(
byte[] buffer,
int offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected override void Dispose(bool disposing)
public override int Read(byte[] buffer, int offset, int count) =>
Read(new Span<byte>(buffer, offset, count));

#if !LEGACY_DOTNET
#if !LEGACY_DOTNET || NETSTANDARD2_1
public override int Read(Span<byte> buffer)
#else
public int Read(Span<byte> buffer)
Expand Down Expand Up @@ -203,7 +203,7 @@ private void EnsureNotDisposed()
}
}

#if LEGACY_DOTNET
#if LEGACY_DOTNET && !NETSTANDARD2_1
public virtual Task DisposeAsync()
{
try
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Polyfills/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Skip(long advanceAmount)
public Task SkipAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
#if NET8_0_OR_GREATER
#if NET5_0_OR_GREATER
return stream.CopyToAsync(Stream.Null, cancellationToken);
#else
return stream.CopyToAsync(Stream.Null);
Expand Down
10 changes: 5 additions & 5 deletions src/SharpCompress/SharpCompress.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<FileVersion>0.0.0.0</FileVersion>
<Authors>Adam Hathcock</Authors>
<TargetFrameworks>net48;netstandard2.0;net8.0;net10.0</TargetFrameworks>
<TargetFrameworks>net48;netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
<AssemblyName>SharpCompress</AssemblyName>
<AssemblyOriginatorKeyFile>../../SharpCompress.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand All @@ -17,7 +17,7 @@
<Copyright>Copyright (c) 2025 Adam Hathcock</Copyright>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Description>SharpCompress is a compression library for NET 4.8/NET Standard 2.0/NET 8.0/NET 10.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.</Description>
<Description>SharpCompress is a compression library for NET 4.8/NET Standard 2.0/NET Standard 2.1/NET 5.0/NET 6.0/NET 7.0/NET 8.0/NET 9.0/NET 10.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.</Description>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<DebugType>embedded</DebugType>
Expand All @@ -28,14 +28,14 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' Or '$(TargetFramework)' == 'netstandard2.0' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' Or '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard2.1' ">
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET Standard 2.1 is being marked as LEGACY_DOTNET, which may cause confusion since .NET Standard 2.1 has Span and other modern APIs. The code already handles this with conditional checks like !LEGACY_DOTNET || NETSTANDARD2_1 throughout the codebase, but this creates complexity. Consider whether netstandard2.1 should be excluded from LEGACY_DOTNET definition, or alternatively, verify that all LEGACY_DOTNET usages correctly account for netstandard2.1's capabilities with explicit NETSTANDARD2_1 checks where needed.

Suggested change
<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' Or '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard2.1' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' Or '$(TargetFramework)' == 'netstandard2.0' ">

Copilot uses AI. Check for mistakes.
<DefineConstants>$(DefineConstants);LEGACY_DOTNET</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'net10.0' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'net9.0' Or '$(TargetFramework)' == 'net10.0' ">
<IsTrimmable>true</IsTrimmable>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
Comment on lines +34 to 37
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IsTrimmable and IsAotCompatible properties are only set for net8.0 and net10.0, but net9.0 is also added as a target framework. Consider adding net9.0 to this condition if trimming and AOT compatibility should also apply to net9.0 builds.

Copilot uses AI. Check for mistakes.
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' Or '$(TargetFramework)' == 'netstandard2.0' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' Or '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard2.1' ">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
<PackageReference Include="System.Text.Encoding.CodePages" />
<PackageReference Include="System.Buffers" />
Expand Down
Loading