Some clean up

This commit is contained in:
Adam Hathcock
2026-08-01 12:43:44 +01:00
parent cfdfad26b6
commit bc06a9df8b
5 changed files with 39 additions and 47 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Common;
@@ -31,11 +30,11 @@ internal partial class RarCrcStream : RarStream
.ConfigureAwait(false);
if (result != 0)
{
currentCrc = RarCRC.CheckCrc(currentCrc, buffer, offset, result);
_currentCrc = RarCRC.CheckCrc(_currentCrc, buffer, offset, result);
}
else if (
!disableCRC
&& GetCrc() != BitConverter.ToUInt32(readStream.NotNull().CurrentCrc.NotNull(), 0)
!_disableCrc
&& GetCrc() != BitConverter.ToUInt32(_readStream.NotNull().CurrentCrc.NotNull(), 0)
&& count != 0
)
{
@@ -56,16 +55,16 @@ internal partial class RarCrcStream : RarStream
var result = await base.ReadAsync(buffer, cancellationToken).ConfigureAwait(false);
if (result != 0)
{
currentCrc = RarCRC.CheckCrc(currentCrc, buffer.Span, 0, result);
_currentCrc = RarCRC.CheckCrc(_currentCrc, buffer.Span, 0, result);
}
else if (
!disableCRC
&& GetCrc() != BitConverter.ToUInt32(readStream.NotNull().CurrentCrc.NotNull(), 0)
!_disableCrc
&& GetCrc() != BitConverter.ToUInt32(_readStream.NotNull().CurrentCrc.NotNull(), 0)
&& buffer.Length != 0
)
{
// NOTE: we use the last FileHeader in a multipart volume to check CRC
throw new InvalidFormatException("file crc mismatch");
throw new InvalidFormatException("file crc mismatch: " + _key);
}
return result;

View File

@@ -1,7 +1,4 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Common;
using SharpCompress.Common.Rar.Headers;
@@ -9,9 +6,10 @@ namespace SharpCompress.Compressors.Rar;
internal partial class RarCrcStream : RarStream
{
private readonly MultiVolumeReadOnlyStreamBase readStream;
private uint currentCrc;
private readonly bool disableCRC;
private readonly string? _key;
private readonly MultiVolumeReadOnlyStreamBase _readStream;
private uint _currentCrc;
private readonly bool _disableCrc;
private RarCrcStream(
IRarUnpack unpack,
@@ -20,8 +18,9 @@ internal partial class RarCrcStream : RarStream
)
: base(unpack, fileHeader, readStream)
{
this.readStream = readStream;
disableCRC = fileHeader.IsEncrypted;
this._readStream = readStream;
_key = fileHeader.FileName;
_disableCrc = fileHeader.IsEncrypted;
ResetCrc();
}
@@ -36,31 +35,25 @@ internal partial class RarCrcStream : RarStream
}
// Async methods moved to RarCrcStream.Async.cs
public uint GetCrc() => ~_currentCrc;
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
public uint GetCrc() => ~currentCrc;
public void ResetCrc() => currentCrc = 0xffffffff;
public void ResetCrc() => _currentCrc = 0xffffffff;
public override int Read(byte[] buffer, int offset, int count)
{
var result = base.Read(buffer, offset, count);
if (result != 0)
{
currentCrc = RarCRC.CheckCrc(currentCrc, buffer, offset, result);
_currentCrc = RarCRC.CheckCrc(_currentCrc, buffer, offset, result);
}
else if (
!disableCRC
&& GetCrc() != BitConverter.ToUInt32(readStream.NotNull().CurrentCrc.NotNull(), 0)
!_disableCrc
&& GetCrc() != BitConverter.ToUInt32(_readStream.NotNull().CurrentCrc.NotNull(), 0)
&& count != 0
)
{
// NOTE: we use the last FileHeader in a multipart volume to check CRC
throw new InvalidFormatException("file crc mismatch");
throw new InvalidFormatException("file crc mismatch: " + _key);
}
return result;

View File

@@ -321,9 +321,9 @@
"net10.0": {
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[10.0.9, )",
"resolved": "10.0.9",
"contentHash": "4Iw41e2h7I4t70SJcX2GCmbyKJIlA273Cfm9RJMM050/3VBejGAG1KcthP5Z2L6SQcbfbf6BhNWO26+ZG+GzMg=="
"requested": "[10.0.10, )",
"resolved": "10.0.10",
"contentHash": "f5VCIE7AJpd5YvzNTeMGVzQIgyE9tX+AreTYwQF+REbu+DZo/2Ae+jNSwhPEYrVz6RRkd7y8ubXjk6Nn6Ka+Cg=="
},
"Microsoft.NETFramework.ReferenceAssemblies": {
"type": "Direct",
@@ -441,9 +441,9 @@
"net8.0": {
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[8.0.28, )",
"resolved": "8.0.28",
"contentHash": "XMqgVjlLxLqWmEh3c49haXLQwsMNtvo6YscUaqfvEGfg1iA8hnYgkUVq3i9Zu9gKeNKMWiiZKVwZExc/qyEAsQ=="
"requested": "[8.0.29, )",
"resolved": "8.0.29",
"contentHash": "HSBTfrkIZijz8z3ybLRKB7E8rHk4QQufFwpHa9fc5CMIgRhRzdn4mBGmlyXZqaueiMPtuJcnjresGvSTfaW8Mg=="
},
"Microsoft.NETFramework.ReferenceAssemblies": {
"type": "Direct",