11using System ;
2- using System . IO ;
3- using System . Threading ;
4- using System . Threading . Tasks ;
52using SharpCompress . Common ;
63using SharpCompress . Common . Rar . Headers ;
74
85namespace SharpCompress . Compressors . Rar ;
96
107internal partial class RarCrcStream : RarStream
118{
12- private readonly MultiVolumeReadOnlyStreamBase readStream ;
13- private uint currentCrc ;
14- private readonly bool disableCRC ;
9+ private readonly string ? _key ;
10+ private readonly MultiVolumeReadOnlyStreamBase _readStream ;
11+ private uint _currentCrc ;
12+ private readonly bool _disableCrc ;
1513
1614 private RarCrcStream (
1715 IRarUnpack unpack ,
@@ -20,8 +18,9 @@ MultiVolumeReadOnlyStreamBase readStream
2018 )
2119 : base ( unpack , fileHeader , readStream )
2220 {
23- this . readStream = readStream ;
24- disableCRC = fileHeader . IsEncrypted ;
21+ this . _readStream = readStream ;
22+ _key = fileHeader . FileName ;
23+ _disableCrc = fileHeader . IsEncrypted ;
2524 ResetCrc ( ) ;
2625 }
2726
@@ -36,31 +35,25 @@ MultiVolumeReadOnlyStream readStream
3635 }
3736
3837 // Async methods moved to RarCrcStream.Async.cs
38+ public uint GetCrc ( ) => ~ _currentCrc ;
3939
40- protected override void Dispose ( bool disposing )
41- {
42- base . Dispose ( disposing ) ;
43- }
44-
45- public uint GetCrc ( ) => ~ currentCrc ;
46-
47- public void ResetCrc ( ) => currentCrc = 0xffffffff ;
40+ public void ResetCrc ( ) => _currentCrc = 0xffffffff ;
4841
4942 public override int Read ( byte [ ] buffer , int offset , int count )
5043 {
5144 var result = base . Read ( buffer , offset , count ) ;
5245 if ( result != 0 )
5346 {
54- currentCrc = RarCRC . CheckCrc ( currentCrc , buffer , offset , result ) ;
47+ _currentCrc = RarCRC . CheckCrc ( _currentCrc , buffer , offset , result ) ;
5548 }
5649 else if (
57- ! disableCRC
58- && GetCrc ( ) != BitConverter . ToUInt32 ( readStream . NotNull ( ) . CurrentCrc . NotNull ( ) , 0 )
50+ ! _disableCrc
51+ && GetCrc ( ) != BitConverter . ToUInt32 ( _readStream . NotNull ( ) . CurrentCrc . NotNull ( ) , 0 )
5952 && count != 0
6053 )
6154 {
6255 // NOTE: we use the last FileHeader in a multipart volume to check CRC
63- throw new InvalidFormatException ( "file crc mismatch" ) ;
56+ throw new InvalidFormatException ( "file crc mismatch: " + _key ) ;
6457 }
6558
6659 return result ;
0 commit comments