diff --git a/.editorconfig b/.editorconfig
index ec46ee72..fa78f699 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -299,6 +299,19 @@ dotnet_diagnostic.CA2251.severity = error
dotnet_diagnostic.CA2252.severity = none
dotnet_diagnostic.CA2254.severity = suggestion
+; High volume analyzers requiring extensive refactoring - set to suggestion temporarily
+dotnet_diagnostic.CA1835.severity = suggestion
+dotnet_diagnostic.CA1510.severity = suggestion
+dotnet_diagnostic.CA1512.severity = suggestion
+dotnet_diagnostic.CA1844.severity = suggestion
+dotnet_diagnostic.CA1825.severity = suggestion
+dotnet_diagnostic.CA1712.severity = suggestion
+dotnet_diagnostic.CA2022.severity = suggestion
+dotnet_diagnostic.CA1850.severity = suggestion
+dotnet_diagnostic.CA2263.severity = suggestion
+dotnet_diagnostic.CA2012.severity = suggestion
+dotnet_diagnostic.CA1001.severity = suggestion
+
dotnet_diagnostic.CS0169.severity = error
dotnet_diagnostic.CS0219.severity = error
dotnet_diagnostic.CS0649.severity = suggestion
@@ -318,9 +331,9 @@ dotnet_diagnostic.MVC1000.severity = suggestion
dotnet_diagnostic.RZ10012.severity = error
-dotnet_diagnostic.IDE0004.severity = error # redundant cast
+dotnet_diagnostic.IDE0004.severity = suggestion # redundant cast
dotnet_diagnostic.IDE0005.severity = suggestion
-dotnet_diagnostic.IDE0007.severity = error # Use var
+dotnet_diagnostic.IDE0007.severity = suggestion # Use var
dotnet_diagnostic.IDE0011.severity = error # Use braces on if statements
dotnet_diagnostic.IDE0010.severity = silent # populate switch
dotnet_diagnostic.IDE0017.severity = suggestion # initialization can be simplified
@@ -334,7 +347,7 @@ dotnet_diagnostic.IDE0028.severity = silent # expression body for accessors
dotnet_diagnostic.IDE0032.severity = suggestion # Use auto property
dotnet_diagnostic.IDE0033.severity = error # prefer tuple name
dotnet_diagnostic.IDE0037.severity = suggestion # simplify anonymous type
-dotnet_diagnostic.IDE0040.severity = error # modifiers required
+dotnet_diagnostic.IDE0040.severity = suggestion # modifiers required
dotnet_diagnostic.IDE0041.severity = error # simplify null
dotnet_diagnostic.IDE0042.severity = error # deconstruct variable
dotnet_diagnostic.IDE0044.severity = suggestion # make field only when possible
@@ -359,7 +372,7 @@ dotnet_diagnostic.IDE0200.severity = suggestion # lambda not needed
dotnet_diagnostic.IDE1006.severity = suggestion # Naming rule violation: These words cannot contain lower case characters
dotnet_diagnostic.IDE0260.severity = suggestion # Use pattern matching
dotnet_diagnostic.IDE0270.severity = suggestion # Null check simplifcation
-dotnet_diagnostic.IDE0290.severity = error # Primary Constructor
+dotnet_diagnostic.IDE0290.severity = suggestion # Primary Constructor
dotnet_diagnostic.IDE0300.severity = suggestion # Collection
dotnet_diagnostic.IDE0305.severity = suggestion # Collection ToList
diff --git a/Directory.Build.props b/Directory.Build.props
index f03c2d6e..277c525f 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -8,8 +8,6 @@
true
true
true
- False
- False
true
true
true
diff --git a/build/Program.cs b/build/Program.cs
index bfeb60b9..82c4d75a 100644
--- a/build/Program.cs
+++ b/build/Program.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
@@ -114,14 +115,19 @@ Target(
{
var (version, isPrerelease) = await GetVersion();
Console.WriteLine($"VERSION={version}");
- Console.WriteLine($"PRERELEASE={isPrerelease.ToString().ToLower()}");
+ Console.WriteLine(
+ $"PRERELEASE={isPrerelease.ToString().ToLower(CultureInfo.InvariantCulture)}"
+ );
// Write to environment file for GitHub Actions
var githubOutput = Environment.GetEnvironmentVariable("GITHUB_OUTPUT");
if (!string.IsNullOrEmpty(githubOutput))
{
File.AppendAllText(githubOutput, $"version={version}\n");
- File.AppendAllText(githubOutput, $"prerelease={isPrerelease.ToString().ToLower()}\n");
+ File.AppendAllText(
+ githubOutput,
+ $"prerelease={isPrerelease.ToString().ToLower(CultureInfo.InvariantCulture)}\n"
+ );
}
}
);
@@ -363,9 +369,13 @@ Target(
: "⚪";
if (timeChange > 25 || memChange > 25)
+ {
hasRegressions = true;
+ }
if (timeChange < -25 || memChange < -25)
+ {
hasImprovements = true;
+ }
output.Add(
$"| {method} | {baseline.Mean} | {current.Mean} | {timeIcon} {timeChange:+0.0;-0.0;0}% | {baseline.Memory} | {current.Memory} | {memIcon} {memChange:+0.0;-0.0;0}% |"
@@ -545,7 +555,10 @@ static async Task GetGitOutput(string command, string args)
}
catch (Exception ex)
{
- throw new Exception($"Git command failed: git {command} {args}\n{ex.Message}", ex);
+ throw new InvalidOperationException(
+ $"Git command failed: git {command} {args}\n{ex.Message}",
+ ex
+ );
}
}
@@ -575,7 +588,7 @@ static Dictionary ParseBenchmarkResults(string markdown
var line = lines[i].Trim();
// Look for table rows with benchmark data
- if (line.StartsWith("|") && line.Contains("'") && i > 0)
+ if (line.StartsWith('|') && line.Contains("'", StringComparison.Ordinal) && i > 0)
{
var parts = line.Split('|', StringSplitOptions.TrimEntries);
if (parts.Length >= 5)
@@ -588,10 +601,10 @@ static Dictionary ParseBenchmarkResults(string markdown
for (int j = parts.Length - 2; j >= 2; j--)
{
if (
- parts[j].Contains("KB")
- || parts[j].Contains("MB")
- || parts[j].Contains("GB")
- || parts[j].Contains("B")
+ parts[j].Contains("KB", StringComparison.Ordinal)
+ || parts[j].Contains("MB", StringComparison.Ordinal)
+ || parts[j].Contains("GB", StringComparison.Ordinal)
+ || parts[j].Contains('B')
)
{
memoryStr = parts[j];
@@ -624,17 +637,21 @@ static Dictionary ParseBenchmarkResults(string markdown
static double ParseTimeValue(string timeStr)
{
if (string.IsNullOrWhiteSpace(timeStr) || timeStr == "N/A" || timeStr == "NA")
+ {
return 0;
+ }
// Remove thousands separators and parse
timeStr = timeStr.Replace(",", "").Trim();
var match = Regex.Match(timeStr, @"([\d.]+)\s*(\w+)");
if (!match.Success)
+ {
return 0;
+ }
var value = double.Parse(match.Groups[1].Value);
- var unit = match.Groups[2].Value.ToLower();
+ var unit = match.Groups[2].Value.ToLower(CultureInfo.InvariantCulture);
// Convert to microseconds for comparison
return unit switch
@@ -650,16 +667,20 @@ static double ParseTimeValue(string timeStr)
static double ParseMemoryValue(string memStr)
{
if (string.IsNullOrWhiteSpace(memStr) || memStr == "N/A" || memStr == "NA")
+ {
return 0;
+ }
memStr = memStr.Replace(",", "").Trim();
var match = Regex.Match(memStr, @"([\d.]+)\s*(\w+)");
if (!match.Success)
+ {
return 0;
+ }
var value = double.Parse(match.Groups[1].Value);
- var unit = match.Groups[2].Value.ToUpper();
+ var unit = match.Groups[2].Value.ToUpper(CultureInfo.InvariantCulture);
// Convert to KB for comparison
return unit switch
@@ -675,7 +696,9 @@ static double ParseMemoryValue(string memStr)
static double CalculateChange(double baseline, double current)
{
if (baseline == 0)
+ {
return 0;
+ }
return ((current - baseline) / baseline) * 100;
}
diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs b/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs
index afc64bfa..ea3e0b49 100644
--- a/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs
+++ b/src/SharpCompress/Archives/GZip/GZipArchive.Async.cs
@@ -40,10 +40,7 @@ public partial class GZipArchive
{
throw new InvalidFormatException("Only one entry is allowed in a GZip Archive");
}
- await using var writer = new GZipWriter(
- stream,
- options as GZipWriterOptions ?? new GZipWriterOptions(options)
- );
+ await using var writer = new GZipWriter(stream, options);
await foreach (
var entry in oldEntries.WithCancellation(cancellationToken).ConfigureAwait(false)
)
diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.cs b/src/SharpCompress/Archives/GZip/GZipArchive.cs
index 56f61fa5..e3356a9c 100644
--- a/src/SharpCompress/Archives/GZip/GZipArchive.cs
+++ b/src/SharpCompress/Archives/GZip/GZipArchive.cs
@@ -67,10 +67,7 @@ public partial class GZipArchive
{
throw new InvalidFormatException("Only one entry is allowed in a GZip Archive");
}
- using var writer = new GZipWriter(
- stream,
- options as GZipWriterOptions ?? new GZipWriterOptions(options)
- );
+ using var writer = new GZipWriter(stream, options);
foreach (var entry in oldEntries.Concat(newEntries).Where(x => !x.IsDirectory))
{
using var entryStream = entry.OpenEntryStream();
diff --git a/src/SharpCompress/Archives/Tar/TarArchive.Async.cs b/src/SharpCompress/Archives/Tar/TarArchive.Async.cs
index 1cd7dd91..3911ccb0 100644
--- a/src/SharpCompress/Archives/Tar/TarArchive.Async.cs
+++ b/src/SharpCompress/Archives/Tar/TarArchive.Async.cs
@@ -25,10 +25,7 @@ public partial class TarArchive
CancellationToken cancellationToken = default
)
{
- using var writer = new TarWriter(
- stream,
- options as TarWriterOptions ?? new TarWriterOptions(options)
- );
+ using var writer = new TarWriter(stream, options);
await foreach (
var entry in oldEntries.WithCancellation(cancellationToken).ConfigureAwait(false)
)
diff --git a/src/SharpCompress/Archives/Tar/TarArchive.cs b/src/SharpCompress/Archives/Tar/TarArchive.cs
index 70dc93d2..87c5f441 100644
--- a/src/SharpCompress/Archives/Tar/TarArchive.cs
+++ b/src/SharpCompress/Archives/Tar/TarArchive.cs
@@ -124,10 +124,7 @@ public partial class TarArchive
IEnumerable newEntries
)
{
- using var writer = new TarWriter(
- stream,
- options as TarWriterOptions ?? new TarWriterOptions(options)
- );
+ using var writer = new TarWriter(stream, options);
foreach (var entry in oldEntries.Concat(newEntries))
{
if (entry.IsDirectory)
diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs b/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs
index c8139b06..b203a1bd 100644
--- a/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs
+++ b/src/SharpCompress/Archives/Zip/ZipArchive.Async.cs
@@ -79,10 +79,7 @@ public partial class ZipArchive
CancellationToken cancellationToken = default
)
{
- using var writer = new ZipWriter(
- stream,
- options as ZipWriterOptions ?? new ZipWriterOptions(options)
- );
+ using var writer = new ZipWriter(stream, options);
await foreach (
var entry in oldEntries.WithCancellation(cancellationToken).ConfigureAwait(false)
)
diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs
index 8fc423bd..76bb8bd9 100644
--- a/src/SharpCompress/Archives/Zip/ZipArchive.cs
+++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs
@@ -122,10 +122,7 @@ public partial class ZipArchive
IEnumerable newEntries
)
{
- using var writer = new ZipWriter(
- stream,
- options as ZipWriterOptions ?? new ZipWriterOptions(options)
- );
+ using var writer = new ZipWriter(stream, options);
foreach (var entry in oldEntries.Concat(newEntries))
{
if (entry.IsDirectory)
diff --git a/src/SharpCompress/Common/Arj/Headers/ArjHeader.cs b/src/SharpCompress/Common/Arj/Headers/ArjHeader.cs
index a12eb01d..67b1e0d1 100644
--- a/src/SharpCompress/Common/Arj/Headers/ArjHeader.cs
+++ b/src/SharpCompress/Common/Arj/Headers/ArjHeader.cs
@@ -18,7 +18,6 @@ public enum ArjHeaderType
public abstract partial class ArjHeader
{
- private const int FIRST_HDR_SIZE = 34;
private const ushort ARJ_MAGIC = 0xEA60;
public ArjHeader(ArjHeaderType type)
diff --git a/src/SharpCompress/Common/Arj/Headers/ArjMainHeader.cs b/src/SharpCompress/Common/Arj/Headers/ArjMainHeader.cs
index 3f458613..5fbc9486 100644
--- a/src/SharpCompress/Common/Arj/Headers/ArjMainHeader.cs
+++ b/src/SharpCompress/Common/Arj/Headers/ArjMainHeader.cs
@@ -10,9 +10,6 @@ namespace SharpCompress.Common.Arj.Headers;
public partial class ArjMainHeader : ArjHeader
{
- private const int FIRST_HDR_SIZE = 34;
- private const ushort ARJ_MAGIC = 0xEA60;
-
public ArchiveEncoding ArchiveEncoding { get; }
public int ArchiverVersionNumber { get; private set; }
diff --git a/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.Async.cs b/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.Async.cs
index 9be7d4e9..9a9b3065 100644
--- a/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.Async.cs
+++ b/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.Async.cs
@@ -44,9 +44,7 @@ internal sealed partial class ArchiveHeader
PosAv = await reader.ReadInt32Async(cancellationToken).ConfigureAwait(false);
if (HasFlag(ArchiveFlagsV4.ENCRYPT_VER))
{
- EncryptionVersion = await reader
- .ReadByteAsync(cancellationToken)
- .ConfigureAwait(false);
+ _ = await reader.ReadByteAsync(cancellationToken).ConfigureAwait(false);
}
}
}
diff --git a/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs b/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs
index d3b5ff25..1f6f147d 100644
--- a/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs
+++ b/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs
@@ -29,7 +29,7 @@ internal sealed partial class ArchiveHeader : RarHeader
PosAv = reader.ReadInt32();
if (HasFlag(ArchiveFlagsV4.ENCRYPT_VER))
{
- EncryptionVersion = reader.ReadByte();
+ _ = reader.ReadByte();
}
}
}
@@ -44,8 +44,6 @@ internal sealed partial class ArchiveHeader : RarHeader
internal int? PosAv { get; private set; }
- private byte? EncryptionVersion { get; set; }
-
public bool? IsEncrypted => IsRar5 ? null : HasFlag(ArchiveFlagsV4.PASSWORD);
public bool OldNumberingFormat => !IsRar5 && !HasFlag(ArchiveFlagsV4.NEW_NUMBERING);
diff --git a/src/SharpCompress/Common/Rar/Headers/FileHeader.Async.cs b/src/SharpCompress/Common/Rar/Headers/FileHeader.Async.cs
index a80d121e..31024882 100644
--- a/src/SharpCompress/Common/Rar/Headers/FileHeader.Async.cs
+++ b/src/SharpCompress/Common/Rar/Headers/FileHeader.Async.cs
@@ -79,7 +79,7 @@ internal partial class FileHeader
CompressionMethod = (byte)((compressionInfo >> 7) & 0x7);
WindowSize = IsDirectory ? 0 : ((size_t)0x20000) << ((compressionInfo >> 10) & 0xf);
- HostOs = await reader
+ _ = await reader
.ReadRarVIntByteAsync(cancellationToken: cancellationToken)
.ConfigureAwait(false);
@@ -222,7 +222,7 @@ internal partial class FileHeader
.ReadUInt32Async(cancellationToken)
.ConfigureAwait(false);
- HostOs = await reader.ReadByteAsync(cancellationToken).ConfigureAwait(false);
+ _ = await reader.ReadByteAsync(cancellationToken).ConfigureAwait(false);
FileCrc = await reader.ReadBytesAsync(4, cancellationToken).ConfigureAwait(false);
diff --git a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs
index 966dc2bc..cbf78503 100644
--- a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs
+++ b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs
@@ -72,7 +72,7 @@ internal partial class FileHeader : RarHeader
// Bits 11 - 14 (0x3c00) define the minimum size of dictionary size required to extract data. Value 0 means 128 KB, 1 - 256 KB, ..., 14 - 2048 MB, 15 - 4096 MB.
WindowSize = IsDirectory ? 0 : ((size_t)0x20000) << ((compressionInfo >> 10) & 0xf);
- HostOs = reader.ReadRarVIntByte();
+ _ = reader.ReadRarVIntByte();
var nameSize = reader.ReadRarVIntUInt16();
@@ -197,7 +197,7 @@ internal partial class FileHeader : RarHeader
var lowUncompressedSize = reader.ReadUInt32();
- HostOs = reader.ReadByte();
+ _ = reader.ReadByte();
FileCrc = reader.ReadBytes(4);
@@ -415,7 +415,6 @@ internal partial class FileHeader : RarHeader
internal byte[]? R4Salt { get; private set; }
internal Rar5CryptoInfo? Rar5CryptoInfo { get; private set; }
- private byte HostOs { get; set; }
internal uint FileAttributes { get; private set; }
internal long CompressedSize { get; private set; }
internal long UncompressedSize { get; private set; }
diff --git a/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs b/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs
index 75471aa9..da46643d 100644
--- a/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs
+++ b/src/SharpCompress/Common/Tar/Headers/TarHeader.Async.cs
@@ -3,6 +3,7 @@ using System.Buffers;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
+using System.IO.Compression;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -26,7 +27,7 @@ internal sealed partial class TarHeader
await WriteUstarAsync(output, cancellationToken).ConfigureAwait(false);
break;
default:
- throw new Exception("This should be impossible...");
+ throw new InvalidOperationException("This should be impossible...");
}
}
@@ -73,7 +74,7 @@ internal sealed partial class TarHeader
if (splitIndex == -1)
{
- throw new Exception(
+ throw new InvalidDataException(
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Directory separator not found! Try using GNU Tar format instead!"
);
}
@@ -83,14 +84,14 @@ internal sealed partial class TarHeader
if (this.ArchiveEncoding.GetEncoding().GetByteCount(namePrefix) >= 155)
{
- throw new Exception(
+ throw new InvalidDataException(
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Try using GNU Tar format instead!"
);
}
if (this.ArchiveEncoding.GetEncoding().GetByteCount(name) >= 100)
{
- throw new Exception(
+ throw new InvalidDataException(
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Try using GNU Tar format instead!"
);
}
diff --git a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs
index 06224cac..f51c2404 100644
--- a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs
+++ b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs
@@ -3,6 +3,7 @@ using System.Buffers;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
+using System.IO.Compression;
using System.Text;
using System.Threading.Tasks;
@@ -51,7 +52,7 @@ internal sealed partial class TarHeader
WriteUstar(output);
break;
default:
- throw new Exception("This should be impossible...");
+ throw new InvalidOperationException("This should be impossible...");
}
}
@@ -103,7 +104,7 @@ internal sealed partial class TarHeader
if (splitIndex == -1)
{
- throw new Exception(
+ throw new InvalidDataException(
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Directory separator not found! Try using GNU Tar format instead!"
);
}
@@ -113,14 +114,14 @@ internal sealed partial class TarHeader
if (this.ArchiveEncoding.GetEncoding().GetByteCount(namePrefix) >= 155)
{
- throw new Exception(
+ throw new InvalidDataException(
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Try using GNU Tar format instead!"
);
}
if (this.ArchiveEncoding.GetEncoding().GetByteCount(name) >= 100)
{
- throw new Exception(
+ throw new InvalidDataException(
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Try using GNU Tar format instead!"
);
}
diff --git a/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs b/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs
index d6c17889..10f6cdf7 100644
--- a/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs
+++ b/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs
@@ -6,7 +6,6 @@ namespace SharpCompress.Common.Tar;
internal class TarReadOnlySubStream : Stream
{
private readonly Stream _stream;
- private readonly bool _useSyncOverAsyncDispose;
private bool _isDisposed;
private long _amountRead;
@@ -14,7 +13,6 @@ internal class TarReadOnlySubStream : Stream
public TarReadOnlySubStream(Stream stream, long bytesToRead, bool useSyncOverAsyncDispose)
{
_stream = stream;
- _useSyncOverAsyncDispose = useSyncOverAsyncDispose;
BytesLeftToRead = bytesToRead;
}
@@ -22,6 +20,7 @@ internal class TarReadOnlySubStream : Stream
{
if (_isDisposed)
{
+ base.Dispose(disposing);
return;
}
@@ -47,6 +46,7 @@ internal class TarReadOnlySubStream : Stream
}
}
}
+ base.Dispose(disposing);
}
#if !LEGACY_DOTNET
@@ -54,6 +54,7 @@ internal class TarReadOnlySubStream : Stream
{
if (_isDisposed)
{
+ await base.DisposeAsync().ConfigureAwait(false);
return;
}
@@ -71,6 +72,7 @@ internal class TarReadOnlySubStream : Stream
}
GC.SuppressFinalize(this);
+ await base.DisposeAsync().ConfigureAwait(false);
}
#endif
diff --git a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.Async.cs b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.Async.cs
index deb4dd10..766f4ecb 100644
--- a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.Async.cs
+++ b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.Async.cs
@@ -13,6 +13,7 @@ internal partial class WinzipAesCryptoStream
{
if (_isDisposed)
{
+ await base.DisposeAsync().ConfigureAwait(false);
return;
}
_isDisposed = true;
@@ -27,6 +28,7 @@ internal partial class WinzipAesCryptoStream
ArrayPool.Shared.Return(authBytes);
await _stream.DisposeAsync().ConfigureAwait(false);
}
+ await base.DisposeAsync().ConfigureAwait(false);
}
#endif
diff --git a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs
index 167f1461..b87e60a5 100644
--- a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs
+++ b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs
@@ -63,6 +63,7 @@ internal partial class WinzipAesCryptoStream : Stream
{
if (_isDisposed)
{
+ base.Dispose(disposing);
return;
}
_isDisposed = true;
@@ -88,6 +89,7 @@ internal partial class WinzipAesCryptoStream : Stream
}
_stream.Dispose();
}
+ base.Dispose(disposing);
}
private async Task ReadAuthBytesAsync()
diff --git a/src/SharpCompress/Compressors/Arj/LhaStream.Async.cs b/src/SharpCompress/Compressors/Arj/LhaStream.Async.cs
index 26d6fe70..fd9b31b6 100644
--- a/src/SharpCompress/Compressors/Arj/LhaStream.Async.cs
+++ b/src/SharpCompress/Compressors/Arj/LhaStream.Async.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.IO.Compression;
using System.Threading;
using System.Threading.Tasks;
@@ -20,7 +21,7 @@ public sealed partial class LhaStream
}
if (offset < 0 || count < 0 || (offset + count) > buffer.Length)
{
- throw new ArgumentOutOfRangeException();
+ throw new ArgumentOutOfRangeException(nameof(offset));
}
if (_producedBytes >= _originalSize)
@@ -116,7 +117,7 @@ public sealed partial class LhaStream
if (numCodes > NUM_TEMP_CODELEN)
{
- throw new Exception("temporary codelen table has invalid size");
+ throw new InvalidDataException("temporary codelen table has invalid size");
}
// read actual lengths
@@ -132,7 +133,7 @@ public sealed partial class LhaStream
if (3 + skip > numCodes)
{
- throw new Exception("temporary codelen table has invalid size");
+ throw new InvalidDataException("temporary codelen table has invalid size");
}
for (int i = 3 + skip; i < numCodes; i++)
@@ -161,7 +162,7 @@ public sealed partial class LhaStream
if (numCodes > NUM_COMMANDS)
{
- throw new Exception("commands codelen table has invalid size");
+ throw new InvalidDataException("commands codelen table has invalid size");
}
int index = 0;
diff --git a/src/SharpCompress/Compressors/Arj/LhaStream.cs b/src/SharpCompress/Compressors/Arj/LhaStream.cs
index 76071b45..c09801c6 100644
--- a/src/SharpCompress/Compressors/Arj/LhaStream.cs
+++ b/src/SharpCompress/Compressors/Arj/LhaStream.cs
@@ -1,6 +1,7 @@
using System;
using System.Data;
using System.IO;
+using System.IO.Compression;
using System.Linq;
namespace SharpCompress.Compressors.Arj;
@@ -10,7 +11,6 @@ public sealed partial class LhaStream : Stream
where C : ILhaDecoderConfig, new()
{
private readonly BitReader _bitReader;
- private readonly Stream _stream;
private readonly HuffTree _commandTree;
private readonly HuffTree _offsetTree;
@@ -27,7 +27,6 @@ public sealed partial class LhaStream : Stream
public LhaStream(Stream compressedStream, int originalSize)
{
- _stream = compressedStream ?? throw new ArgumentNullException(nameof(compressedStream));
_bitReader = new BitReader(compressedStream);
_ringBuffer = _config.RingBuffer;
_commandTree = new HuffTree(NUM_COMMANDS * 2);
@@ -64,7 +63,7 @@ public sealed partial class LhaStream : Stream
}
if (offset < 0 || count < 0 || (offset + count) > buffer.Length)
{
- throw new ArgumentOutOfRangeException();
+ throw new ArgumentOutOfRangeException(nameof(offset));
}
if (_producedBytes >= _originalSize)
@@ -137,7 +136,7 @@ public sealed partial class LhaStream : Stream
if (numCodes > NUM_TEMP_CODELEN)
{
- throw new Exception("temporary codelen table has invalid size");
+ throw new InvalidDataException("temporary codelen table has invalid size");
}
// read actual lengths
@@ -152,7 +151,7 @@ public sealed partial class LhaStream : Stream
if (3 + skip > numCodes)
{
- throw new Exception("temporary codelen table has invalid size");
+ throw new InvalidDataException("temporary codelen table has invalid size");
}
for (int i = 3 + skip; i < numCodes; i++)
@@ -180,7 +179,7 @@ public sealed partial class LhaStream : Stream
if (numCodes > NUM_COMMANDS)
{
- throw new Exception("commands codelen table has invalid size");
+ throw new InvalidDataException("commands codelen table has invalid size");
}
int index = 0;
diff --git a/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs b/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs
index 0aa690f6..e420a9c9 100644
--- a/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs
+++ b/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs
@@ -54,6 +54,7 @@ public sealed partial class BZip2Stream : Stream
{
if (isDisposed || leaveOpen)
{
+ base.Dispose(disposing);
return;
}
isDisposed = true;
@@ -61,6 +62,7 @@ public sealed partial class BZip2Stream : Stream
{
stream.Dispose();
}
+ base.Dispose(disposing);
}
public CompressionMode Mode { get; private set; }
diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs
index f846c3eb..4710aaf5 100644
--- a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs
+++ b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs
@@ -447,6 +447,7 @@ internal sealed class CBZip2OutputStream : Stream
{
if (disposed)
{
+ base.Dispose(disposing);
return;
}
@@ -460,6 +461,7 @@ internal sealed class CBZip2OutputStream : Stream
}
bsStream = null;
}
+ base.Dispose(disposing);
}
public void Finish()
diff --git a/src/SharpCompress/Compressors/Explode/ExplodeStream.Async.cs b/src/SharpCompress/Compressors/Explode/ExplodeStream.Async.cs
index 6eb1afef..16dbfdd9 100644
--- a/src/SharpCompress/Compressors/Explode/ExplodeStream.Async.cs
+++ b/src/SharpCompress/Compressors/Explode/ExplodeStream.Async.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.IO.Compression;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Common.Zip.Headers;
@@ -278,7 +279,7 @@ public partial class ExplodeStream
if (literalResult.returnCode != 0)
{
- throw new Exception("Error decoding literal value");
+ throw new InvalidDataException("Error decoding literal value");
}
huftPointer = literalResult.huftPointer;
@@ -318,7 +319,7 @@ public partial class ExplodeStream
if (distanceResult.returnCode != 0)
{
- throw new Exception("Error decoding distance high bits");
+ throw new InvalidDataException("Error decoding distance high bits");
}
huftPointer = distanceResult.huftPointer;
@@ -334,7 +335,7 @@ public partial class ExplodeStream
if (lengthResult.returnCode != 0)
{
- throw new Exception("Error decoding coded length");
+ throw new InvalidDataException("Error decoding coded length");
}
huftPointer = lengthResult.huftPointer;
diff --git a/src/SharpCompress/Compressors/Explode/ExplodeStream.cs b/src/SharpCompress/Compressors/Explode/ExplodeStream.cs
index 3d1aa2fd..977cd629 100644
--- a/src/SharpCompress/Compressors/Explode/ExplodeStream.cs
+++ b/src/SharpCompress/Compressors/Explode/ExplodeStream.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.IO.Compression;
using SharpCompress.Common.Zip.Headers;
namespace SharpCompress.Compressors.Explode;
@@ -696,7 +697,7 @@ public partial class ExplodeStream : Stream
) != 0
)
{
- throw new Exception("Error decoding literal value");
+ throw new InvalidDataException("Error decoding literal value");
}
nextByte = (byte)huftPointer.Value;
@@ -735,7 +736,7 @@ public partial class ExplodeStream : Stream
) != 0
)
{
- throw new Exception("Error decoding distance high bits");
+ throw new InvalidDataException("Error decoding distance high bits");
}
distance = windowIndex - (distance + huftPointer.Value); /* construct offset */
@@ -751,7 +752,7 @@ public partial class ExplodeStream : Stream
) != 0
)
{
- throw new Exception("Error decoding coded length");
+ throw new InvalidDataException("Error decoding coded length");
}
length = huftPointer.Value;
diff --git a/src/SharpCompress/Compressors/Filters/DeltaFilter.cs b/src/SharpCompress/Compressors/Filters/DeltaFilter.cs
index 5f7593ce..82a76ae9 100644
--- a/src/SharpCompress/Compressors/Filters/DeltaFilter.cs
+++ b/src/SharpCompress/Compressors/Filters/DeltaFilter.cs
@@ -4,7 +4,6 @@ namespace SharpCompress.Compressors.Filters;
internal class DeltaFilter : Filter
{
- private const int DISTANCE_MIN = 1;
private const int DISTANCE_MAX = 256;
private const int DISTANCE_MASK = DISTANCE_MAX - 1;
diff --git a/src/SharpCompress/Compressors/LZMA/LZipStream.cs b/src/SharpCompress/Compressors/LZMA/LZipStream.cs
index 297447c2..67dbf777 100644
--- a/src/SharpCompress/Compressors/LZMA/LZipStream.cs
+++ b/src/SharpCompress/Compressors/LZMA/LZipStream.cs
@@ -99,6 +99,7 @@ public sealed partial class LZipStream : Stream
{
if (_disposed)
{
+ base.Dispose(disposing);
return;
}
_disposed = true;
@@ -111,6 +112,7 @@ public sealed partial class LZipStream : Stream
_originalStream?.Dispose();
}
}
+ base.Dispose(disposing);
}
public CompressionMode Mode { get; }
diff --git a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs
index e9fa1bab..d674cf45 100644
--- a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs
+++ b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs
@@ -281,9 +281,6 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties
}
}
- private const uint K_NUM_LEN_SPEC_SYMBOLS =
- Base.K_NUM_LOW_LEN_SYMBOLS + Base.K_NUM_MID_LEN_SYMBOLS;
-
private class LenPriceTableEncoder : LenEncoder
{
private readonly uint[] _prices = new uint[
@@ -1232,12 +1229,6 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties
}
}
- private bool ChangePair(uint smallDist, uint bigDist)
- {
- const int kDif = 7;
- return (smallDist < ((uint)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif));
- }
-
private void WriteEndMarker(uint posState)
{
if (!_writeEndMark)
diff --git a/src/SharpCompress/Compressors/Lzw/LzwStream.cs b/src/SharpCompress/Compressors/Lzw/LzwStream.cs
index 274abca0..2ae3ad21 100644
--- a/src/SharpCompress/Compressors/Lzw/LzwStream.cs
+++ b/src/SharpCompress/Compressors/Lzw/LzwStream.cs
@@ -559,6 +559,7 @@ public partial class LzwStream : Stream
baseInputStream.Dispose();
}
}
+ base.Dispose(disposing);
}
#endregion Stream Overrides
diff --git a/src/SharpCompress/Compressors/RLE90/RunLength90Stream.Async.cs b/src/SharpCompress/Compressors/RLE90/RunLength90Stream.Async.cs
index e47ac2e1..0b43b60b 100644
--- a/src/SharpCompress/Compressors/RLE90/RunLength90Stream.Async.cs
+++ b/src/SharpCompress/Compressors/RLE90/RunLength90Stream.Async.cs
@@ -21,7 +21,7 @@ public partial class RunLength90Stream
if (offset < 0 || count < 0 || offset + count > buffer.Length)
{
- throw new ArgumentOutOfRangeException();
+ throw new ArgumentOutOfRangeException(nameof(offset));
}
int bytesWritten = 0;
diff --git a/src/SharpCompress/Compressors/RLE90/RunLength90Stream.cs b/src/SharpCompress/Compressors/RLE90/RunLength90Stream.cs
index 178a2220..44f57b57 100644
--- a/src/SharpCompress/Compressors/RLE90/RunLength90Stream.cs
+++ b/src/SharpCompress/Compressors/RLE90/RunLength90Stream.cs
@@ -60,7 +60,7 @@ public partial class RunLength90Stream : Stream
if (offset < 0 || count < 0 || offset + count > buffer.Length)
{
- throw new ArgumentOutOfRangeException();
+ throw new ArgumentOutOfRangeException(nameof(offset));
}
int bytesWritten = 0;
diff --git a/src/SharpCompress/Compressors/Rar/RarBLAKE2spStream.cs b/src/SharpCompress/Compressors/Rar/RarBLAKE2spStream.cs
index fa47181a..92502b90 100644
--- a/src/SharpCompress/Compressors/Rar/RarBLAKE2spStream.cs
+++ b/src/SharpCompress/Compressors/Rar/RarBLAKE2spStream.cs
@@ -54,7 +54,6 @@ internal partial class RarBLAKE2spStream : RarStream
internal byte[] b;
internal int bufferPosition;
internal UInt32 lastNodeFlag;
- UInt32[] dummy;
public BLAKE2S()
{
@@ -62,7 +61,6 @@ internal partial class RarBLAKE2spStream : RarStream
t = new uint[2];
f = new uint[2];
b = new byte[BLAKE2S_BLOCK_SIZE];
- dummy = new uint[2];
}
};
diff --git a/src/SharpCompress/Compressors/Shrink/BitStream.cs b/src/SharpCompress/Compressors/Shrink/BitStream.cs
index fc0d5e53..77df3fa3 100644
--- a/src/SharpCompress/Compressors/Shrink/BitStream.cs
+++ b/src/SharpCompress/Compressors/Shrink/BitStream.cs
@@ -19,7 +19,7 @@ internal class BitStream
31U,
63U,
(uint)sbyte.MaxValue,
- (uint)byte.MaxValue,
+ byte.MaxValue,
511U,
1023U,
2047U,
@@ -27,7 +27,7 @@ internal class BitStream
8191U,
16383U,
(uint)short.MaxValue,
- (uint)ushort.MaxValue,
+ ushort.MaxValue,
};
public BitStream(byte[] src, int srcLen)
@@ -62,7 +62,7 @@ internal class BitStream
_bitsLeft += 8;
}
}
- result = (int)((long)_bitBuffer & (long)_maskBits[nbits]);
+ result = (int)(_bitBuffer & _maskBits[nbits]);
_bitBuffer >>= nbits;
_bitsLeft -= nbits;
return result;
diff --git a/src/SharpCompress/Compressors/Shrink/ShrinkStream.cs b/src/SharpCompress/Compressors/Shrink/ShrinkStream.cs
index dfd61834..97da7431 100644
--- a/src/SharpCompress/Compressors/Shrink/ShrinkStream.cs
+++ b/src/SharpCompress/Compressors/Shrink/ShrinkStream.cs
@@ -7,7 +7,6 @@ namespace SharpCompress.Compressors.Shrink;
internal partial class ShrinkStream : Stream
{
private Stream inStream;
- private CompressionMode _compressionMode;
private ulong _compressedSize;
private long _uncompressedSize;
@@ -24,7 +23,6 @@ internal partial class ShrinkStream : Stream
)
{
inStream = stream;
- _compressionMode = compressionMode;
_compressedSize = (ulong)compressedSize;
_uncompressedSize = uncompressedSize;
diff --git a/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs b/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs
index d1f179b3..9296e680 100644
--- a/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs
+++ b/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs
@@ -10,7 +10,6 @@ namespace SharpCompress.Compressors.Squeezed;
public partial class SqueezeStream : Stream
{
private readonly Stream _stream;
- private readonly int _compressedSize;
private const int NUMVALS = 257;
private const int SPEOF = 256;
@@ -19,7 +18,6 @@ public partial class SqueezeStream : Stream
private SqueezeStream(Stream stream, int compressedSize)
{
_stream = stream ?? throw new ArgumentNullException(nameof(stream));
- _compressedSize = compressedSize;
}
public static SqueezeStream Create(Stream stream, int compressedSize)
diff --git a/src/SharpCompress/Compressors/Xz/XZBlock.cs b/src/SharpCompress/Compressors/Xz/XZBlock.cs
index 39c3f0b5..9642cd51 100644
--- a/src/SharpCompress/Compressors/Xz/XZBlock.cs
+++ b/src/SharpCompress/Compressors/Xz/XZBlock.cs
@@ -19,7 +19,6 @@ public sealed partial class XZBlock : XZReadOnlyStream
public ulong? UncompressedSize { get; private set; }
public Stack Filters { get; private set; } = new();
public bool HeaderIsLoaded { get; private set; }
- private CheckType _checkType;
private readonly int _checkSize;
private bool _streamConnected;
private int _numFilters;
@@ -33,7 +32,6 @@ public sealed partial class XZBlock : XZReadOnlyStream
public XZBlock(Stream stream, CheckType checkType, int checkSize)
: base(stream)
{
- _checkType = checkType;
_checkSize = checkSize;
_startPosition = stream.Position;
}
diff --git a/src/SharpCompress/Compressors/Xz/XZStream.cs b/src/SharpCompress/Compressors/Xz/XZStream.cs
index 489b449a..ea193431 100644
--- a/src/SharpCompress/Compressors/Xz/XZStream.cs
+++ b/src/SharpCompress/Compressors/Xz/XZStream.cs
@@ -12,10 +12,7 @@ namespace SharpCompress.Compressors.Xz;
public sealed partial class XZStream : XZReadOnlyStream
{
public XZStream(Stream baseStream)
- : base(baseStream)
- {
- _baseStream = baseStream;
- }
+ : base(baseStream) { }
protected override void Dispose(bool disposing)
{
@@ -48,7 +45,6 @@ public sealed partial class XZStream : XZReadOnlyStream
}
}
- private readonly Stream _baseStream;
public XZHeader Header { get; private set; }
public XZIndex Index { get; private set; }
public XZFooter Footer { get; private set; }
diff --git a/src/SharpCompress/Compressors/ZStandard/CompressionStream.Async.cs b/src/SharpCompress/Compressors/ZStandard/CompressionStream.Async.cs
index 7a16b500..1baedd30 100644
--- a/src/SharpCompress/Compressors/ZStandard/CompressionStream.Async.cs
+++ b/src/SharpCompress/Compressors/ZStandard/CompressionStream.Async.cs
@@ -16,6 +16,7 @@ public partial class CompressionStream : Stream
{
if (compressor == null)
{
+ await base.DisposeAsync().ConfigureAwait(false);
return;
}
@@ -28,6 +29,7 @@ public partial class CompressionStream : Stream
ReleaseUnmanagedResources();
GC.SuppressFinalize(this);
}
+ await base.DisposeAsync().ConfigureAwait(false);
}
public override async Task FlushAsync(CancellationToken cancellationToken) =>
diff --git a/src/SharpCompress/Compressors/ZStandard/CompressionStream.cs b/src/SharpCompress/Compressors/ZStandard/CompressionStream.cs
index 21e341ce..e61796f8 100644
--- a/src/SharpCompress/Compressors/ZStandard/CompressionStream.cs
+++ b/src/SharpCompress/Compressors/ZStandard/CompressionStream.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Buffers;
using System.IO;
using System.Threading;
@@ -84,6 +84,7 @@ public partial class CompressionStream : Stream
{
if (compressor == null)
{
+ base.Dispose(disposing);
return;
}
@@ -98,6 +99,7 @@ public partial class CompressionStream : Stream
{
ReleaseUnmanagedResources();
}
+ base.Dispose(disposing);
}
private void ReleaseUnmanagedResources()
diff --git a/src/SharpCompress/Compressors/ZStandard/DecompressionStream.cs b/src/SharpCompress/Compressors/ZStandard/DecompressionStream.cs
index 97d28977..b6568a22 100644
--- a/src/SharpCompress/Compressors/ZStandard/DecompressionStream.cs
+++ b/src/SharpCompress/Compressors/ZStandard/DecompressionStream.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Buffers;
using System.IO;
using System.Threading;
@@ -90,6 +90,7 @@ public partial class DecompressionStream : Stream
{
if (decompressor == null)
{
+ base.Dispose(disposing);
return;
}
@@ -108,6 +109,7 @@ public partial class DecompressionStream : Stream
{
innerStream.Dispose();
}
+ base.Dispose(disposing);
}
public override int Read(byte[] buffer, int offset, int count) =>
diff --git a/src/SharpCompress/IO/SharpCompressStream.Async.cs b/src/SharpCompress/IO/SharpCompressStream.Async.cs
index e18a47a1..b3f1b553 100644
--- a/src/SharpCompress/IO/SharpCompressStream.Async.cs
+++ b/src/SharpCompress/IO/SharpCompressStream.Async.cs
@@ -275,6 +275,7 @@ internal partial class SharpCompressStream
_ringBuffer?.Dispose();
_ringBuffer = null;
}
+ await base.DisposeAsync().ConfigureAwait(false);
}
#endif
}