diff --git a/Directory.Build.props b/Directory.Build.props index bcbdc590..bc1b9017 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -32,7 +32,7 @@ CA1710;CA1711;CA1720;CA1724; CA1502;CA1716;NETSDK1206;IDE0017;IDE0032;IDE0040;IDE0044;IDE0051;IDE0052;IDE0060;IDE0251;IDE1006;IDE1007;IDE1033;IDE1036;IDE1040;IDE1041;IDE1045;IDE1050;IDE1051;IDE1055;IDE1060;IDE1063; - IDE1070;IDE1071;IDE1075;IDE1080;IDE1090;CA1027;CA1031;CA1032;CA1033;CA1028;CA1034;CA1051;CA1063;CA1069;CA1505;CA1802;CA1814;CA1819;CA1805;CA2225;CA2237; + IDE1070;IDE1071;IDE1075;IDE1080;IDE1090;CA1024;CA1027;CA1031;CA1032;CA1033;CA1028;CA1034;CA1051;CA1063;CA1069;CA1505;CA1802;CA1814;CA1819;CA1805;CA2214;CA2225;CA2237; $(NoWarn) diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.cs b/src/SharpCompress/Archives/GZip/GZipArchive.cs index 4437ff57..ca3deb7a 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchive.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchive.cs @@ -166,7 +166,7 @@ public class GZipArchive : AbstractWritableArchive bool closeStream ) { - if (Entries.Any()) + if (Entries.Count != 0) { throw new InvalidFormatException("Only one entry is allowed in a GZip Archive"); } diff --git a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs index 6ce9aa44..40255b18 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs @@ -88,8 +88,10 @@ public class RarArchiveEntry : RarEntry, IArchiveEntry { get { +#pragma warning disable CA1851 var headers = parts.Select(x => x.FileHeader); return !headers.First().IsSplitBefore && !headers.Last().IsSplitAfter; +#pragma warning restore CA1851 } } diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs index 9b55823a..a3a4a9e7 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs @@ -225,7 +225,7 @@ public class ZipArchive : AbstractWritableArchive var streams = stream.Streams.ToList(); var idx = 0; - if (streams.Count() > 1) //test part 2 - true = multipart not split + if (streams.Count > 1) //test part 2 - true = multipart not split { streams[1].Position += 4; //skip the POST_DATA_DESCRIPTOR to prevent an exception var isZip = IsZipFile(streams[1], ReaderOptions.Password, ReaderOptions.BufferSize); diff --git a/src/SharpCompress/Common/Arc/ArcEntry.cs b/src/SharpCompress/Common/Arc/ArcEntry.cs index 7ee81c40..a11c2048 100644 --- a/src/SharpCompress/Common/Arc/ArcEntry.cs +++ b/src/SharpCompress/Common/Arc/ArcEntry.cs @@ -33,7 +33,9 @@ public class ArcEntry : Entry public override CompressionType CompressionType => _filePart?.Header.CompressionMethod ?? CompressionType.Unknown; +#pragma warning disable CA1065 public override long Size => throw new NotImplementedException(); +#pragma warning restore CA1065 public override DateTime? LastModifiedTime => null; diff --git a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs index 5464a9cc..76d7c542 100644 --- a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs @@ -47,9 +47,9 @@ internal sealed class StreamingZipFilePart : ZipFilePart // If we had TotalIn / TotalOut we could have used them Header.CompressedSize = _decompressionStream.Position; - if (_decompressionStream is DeflateStream deflateStream) + if (_decompressionStream is DeflateStream) { - ((IStreamStack)rewindableStream).StackSeek(0); + rewindableStream.StackSeek(0); } Skipped = true; diff --git a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs index fd489dc2..f8e9d58d 100644 --- a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs @@ -175,7 +175,7 @@ internal class StreamingZipHeaderFactory : ZipHeaderFactory && local_header.CompressedSize == 0 && local_header.UncompressedSize == 0 && local_header.Crc == 0 - && local_header.IsDirectory == false + && !local_header.IsDirectory ); if (dir_header != null) @@ -193,7 +193,7 @@ internal class StreamingZipHeaderFactory : ZipHeaderFactory else if (local_header.Flags.HasFlag(HeaderFlags.UsePostDataDescriptor)) { var nextHeaderBytes = reader.ReadUInt32(); - ((IStreamStack)rewindableStream).Rewind(sizeof(uint)); + rewindableStream.Rewind(sizeof(uint)); // Check if next data is PostDataDescriptor, streamed file with 0 length header.HasData = !IsHeader(nextHeaderBytes); diff --git a/src/SharpCompress/Compressors/ADC/ADCStream.cs b/src/SharpCompress/Compressors/ADC/ADCStream.cs index 70e8fd8b..bdb9a32f 100644 --- a/src/SharpCompress/Compressors/ADC/ADCStream.cs +++ b/src/SharpCompress/Compressors/ADC/ADCStream.cs @@ -152,11 +152,9 @@ public sealed class ADCStream : Stream, IStreamStack throw new ArgumentOutOfRangeException(nameof(count)); } - var size = -1; - if (_outBuffer is null) { - size = ADCBase.Decompress(_stream, out _outBuffer); + var _ = ADCBase.Decompress(_stream, out _outBuffer); _outPosition = 0; } @@ -172,7 +170,7 @@ public sealed class ADCStream : Stream, IStreamStack copied += piece; _position += piece; toCopy -= piece; - size = ADCBase.Decompress(_stream, out _outBuffer); + int size = ADCBase.Decompress(_stream, out _outBuffer); _outPosition = 0; if (size == 0 || _outBuffer is null || _outBuffer.Length == 0) { diff --git a/src/SharpCompress/Compressors/ArcLzw/ArcLzwStream.cs b/src/SharpCompress/Compressors/ArcLzw/ArcLzwStream.cs index 828b2f56..56c2059f 100644 --- a/src/SharpCompress/Compressors/ArcLzw/ArcLzwStream.cs +++ b/src/SharpCompress/Compressors/ArcLzw/ArcLzwStream.cs @@ -130,7 +130,7 @@ public partial class ArcLzwStream : Stream, IStreamStack { Array.Clear(prefix, 0, prefix.Length); clearFlag = true; - freeEnt = (ushort)(FIRST - 1); + freeEnt = FIRST - 1; if (GetCode(reader) is ushort c) { @@ -181,7 +181,9 @@ public partial class ArcLzwStream : Stream, IStreamStack public override bool CanRead => true; public override bool CanSeek => false; public override bool CanWrite => false; +#pragma warning disable CA1065 public override long Length => throw new NotImplementedException(); +#pragma warning restore CA1065 public override long Position { get => _stream.Position; diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs index 50df7200..31a5cf67 100644 --- a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs +++ b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs @@ -1306,8 +1306,7 @@ internal sealed class CBZip2OutputStream : Stream, IStreamStack n = block[zptr[unLo] + d + 1] - med; if (n == 0) { - var temp = 0; - temp = zptr[unLo]; + var temp = zptr[unLo]; zptr[unLo] = zptr[ltLo]; zptr[ltLo] = temp; ltLo++; @@ -1330,8 +1329,7 @@ internal sealed class CBZip2OutputStream : Stream, IStreamStack n = block[zptr[unHi] + d + 1] - med; if (n == 0) { - var temp = 0; - temp = zptr[unHi]; + var temp = zptr[unHi]; zptr[unHi] = zptr[gtHi]; zptr[gtHi] = temp; gtHi--; diff --git a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs index 155a3556..8ec2d38b 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs @@ -386,7 +386,7 @@ internal class ZlibBaseStream : Stream, IStreamStack { _stream.Flush(); //rewind the buffer - ((IStreamStack)this).Rewind(z.AvailableBytesIn); //unused + this.Rewind(z.AvailableBytesIn); //unused z.AvailableBytesIn = 0; } @@ -671,7 +671,7 @@ internal class ZlibBaseStream : Stream, IStreamStack if (rc == ZlibConstants.Z_STREAM_END && z.AvailableBytesIn != 0 && !_wantCompress) { //rewind the buffer - ((IStreamStack)this).Rewind(z.AvailableBytesIn); //unused + this.Rewind(z.AvailableBytesIn); //unused z.AvailableBytesIn = 0; } diff --git a/src/SharpCompress/Compressors/Explode/ExplodeStream.cs b/src/SharpCompress/Compressors/Explode/ExplodeStream.cs index 0215c45d..087089fd 100644 --- a/src/SharpCompress/Compressors/Explode/ExplodeStream.cs +++ b/src/SharpCompress/Compressors/Explode/ExplodeStream.cs @@ -70,7 +70,7 @@ public class ExplodeStream : Stream, IStreamStack this.DebugConstruct(typeof(ExplodeStream)); #endif this.compressedSize = (int)compressedSize; - unCompressedSize = (long)uncompressedSize; + unCompressedSize = uncompressedSize; this.generalPurposeBitFlag = generalPurposeBitFlag; explode_SetTables(); @@ -580,7 +580,7 @@ public class ExplodeStream : Stream, IStreamStack if ((returnCode = get_tree(arrBitLengthsForCodes, 64)) != 0) { - return (int)returnCode; + return returnCode; } if ((generalPurposeBitFlag & HeaderFlags.Bit1) != 0) /* true if 8K */ diff --git a/src/SharpCompress/Compressors/Filters/BCJFilterRISCV.cs b/src/SharpCompress/Compressors/Filters/BCJFilterRISCV.cs index 345741e8..077a530b 100644 --- a/src/SharpCompress/Compressors/Filters/BCJFilterRISCV.cs +++ b/src/SharpCompress/Compressors/Filters/BCJFilterRISCV.cs @@ -78,7 +78,7 @@ internal class BCJFilterRISCV : Filter else { uint inst2_rs1 = inst >> 27; - if ((uint)(((inst) - 0x3117) << 18) >= ((inst2_rs1) & 0x1D)) + if (((inst) - 0x3117) << 18 >= ((inst2_rs1) & 0x1D)) { i += 4 - 2; continue; @@ -175,7 +175,7 @@ internal class BCJFilterRISCV : Filter else { uint fake_rs1 = inst >> 27; - if ((uint)(((inst) - 0x3117) << 18) >= ((fake_rs1) & 0x1D)) + if (((inst) - 0x3117) << 18 >= ((fake_rs1) & 0x1D)) { i += 4 - 2; continue; diff --git a/src/SharpCompress/Compressors/LZMA/LZipStream.cs b/src/SharpCompress/Compressors/LZMA/LZipStream.cs index 26d34d3a..5033f7c4 100644 --- a/src/SharpCompress/Compressors/LZMA/LZipStream.cs +++ b/src/SharpCompress/Compressors/LZMA/LZipStream.cs @@ -99,7 +99,7 @@ public sealed class LZipStream : Stream, IStreamStack //total with headers BinaryPrimitives.WriteUInt64LittleEndian( intBuf, - (ulong)compressedCount + (ulong)(6 + 20) + (ulong)compressedCount + (6 + 20) ); _countingWritableSubStream?.Write(intBuf); } diff --git a/src/SharpCompress/Compressors/Reduce/ReduceStream.cs b/src/SharpCompress/Compressors/Reduce/ReduceStream.cs index 7fb30e2c..c9e3df65 100644 --- a/src/SharpCompress/Compressors/Reduce/ReduceStream.cs +++ b/src/SharpCompress/Compressors/Reduce/ReduceStream.cs @@ -141,13 +141,13 @@ public class ReduceStream : Stream, IStreamStack if (nbits > bitBufferCount) { int temp; - while (bitBufferCount <= 8 * (int)(4 - 1) && (temp = NEXTBYTE()) != EOF) + while (bitBufferCount <= 8 * (4 - 1) && (temp = NEXTBYTE()) != EOF) { bitBuffer |= (ulong)temp << bitBufferCount; bitBufferCount += 8; } } - zdest = (byte)(bitBuffer & (ulong)mask_bits[nbits]); + zdest = (byte)(bitBuffer & mask_bits[nbits]); bitBuffer >>= nbits; bitBufferCount -= nbits; } diff --git a/src/SharpCompress/Compressors/Shrink/BitStream.cs b/src/SharpCompress/Compressors/Shrink/BitStream.cs index 8b657cf1..ae5ab9c1 100644 --- a/src/SharpCompress/Compressors/Shrink/BitStream.cs +++ b/src/SharpCompress/Compressors/Shrink/BitStream.cs @@ -61,7 +61,7 @@ internal class BitStream _bitsLeft += 8; } } - result = (int)((long)_bitBuffer & (long)_maskBits[nbits]); + result = (int)((long)_bitBuffer & _maskBits[nbits]); _bitBuffer >>= nbits; _bitsLeft -= nbits; return result; diff --git a/src/SharpCompress/Compressors/Shrink/HwUnshrink.cs b/src/SharpCompress/Compressors/Shrink/HwUnshrink.cs index 31935bfd..8c9c1711 100644 --- a/src/SharpCompress/Compressors/Shrink/HwUnshrink.cs +++ b/src/SharpCompress/Compressors/Shrink/HwUnshrink.cs @@ -80,7 +80,7 @@ public static class HwUnshrink int code, controlCode; - code = (int)stream.NextBits(codeSize); + code = stream.NextBits(codeSize); if (!stream.Advance(codeSize)) { nextCode = INVALID_CODE; diff --git a/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs b/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs index de03cf41..18ff9520 100644 --- a/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs +++ b/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs @@ -129,7 +129,7 @@ public class SqueezeStream : Stream, IStreamStack // Unpack the decoded buffer using the RLE class var unpacked = RLE.UnpackRLE(decoded.ToArray()); unpacked.CopyTo(buffer, 0); - return unpacked.Count(); + return unpacked.Count; } public override long Seek(long offset, SeekOrigin origin) => diff --git a/src/SharpCompress/Compressors/Xz/XZBlock.cs b/src/SharpCompress/Compressors/Xz/XZBlock.cs index cdb075ef..9da955cd 100644 --- a/src/SharpCompress/Compressors/Xz/XZBlock.cs +++ b/src/SharpCompress/Compressors/Xz/XZBlock.cs @@ -99,7 +99,7 @@ public sealed class XZBlock : XZReadOnlyStream private void ConnectStream() { _decomStream = BaseStream; - while (Filters.Any()) + while (Filters.Count > 0) { var filter = Filters.Pop(); filter.SetBaseStream(_decomStream); diff --git a/src/SharpCompress/Compressors/Xz/XZIndex.cs b/src/SharpCompress/Compressors/Xz/XZIndex.cs index 24c43c8a..d7c5b6f5 100644 --- a/src/SharpCompress/Compressors/Xz/XZIndex.cs +++ b/src/SharpCompress/Compressors/Xz/XZIndex.cs @@ -79,7 +79,7 @@ public class XZIndex private void VerifyCrc32() { - var crc = _reader.ReadLittleEndianUInt32(); + //var crc = _reader.ReadLittleEndianUInt32(); // TODO verify this matches } } diff --git a/src/SharpCompress/Compressors/ZStandard/ZStandardStream.cs b/src/SharpCompress/Compressors/ZStandard/ZStandardStream.cs index 35ca8267..d07e1e68 100644 --- a/src/SharpCompress/Compressors/ZStandard/ZStandardStream.cs +++ b/src/SharpCompress/Compressors/ZStandard/ZStandardStream.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text; using SharpCompress.IO; namespace SharpCompress.Compressors.ZStandard; @@ -30,7 +31,7 @@ internal class ZStandardStream : ZstdSharp.DecompressionStream, IStreamStack internal static bool IsZStandard(Stream stream) { - var br = new BinaryReader(stream); + using var br = new BinaryReader(stream, Encoding.UTF8, true); var magic = br.ReadUInt32(); if (ZstandardConstants.MAGIC != magic) { diff --git a/src/SharpCompress/Factories/Factory.cs b/src/SharpCompress/Factories/Factory.cs index a8413686..017d6ded 100644 --- a/src/SharpCompress/Factories/Factory.cs +++ b/src/SharpCompress/Factories/Factory.cs @@ -78,11 +78,11 @@ public abstract class Factory : IFactory if (this is IReaderFactory readerFactory) { - long pos = ((IStreamStack)stream).GetPosition(); + long pos = stream.GetPosition(); if (IsArchive(stream, options.Password, options.BufferSize)) { - ((IStreamStack)stream).StackSeek(pos); + stream.StackSeek(pos); reader = readerFactory.OpenReader(stream, options); return true; } diff --git a/src/SharpCompress/Factories/GZipFactory.cs b/src/SharpCompress/Factories/GZipFactory.cs index 17f344cf..eb25a522 100644 --- a/src/SharpCompress/Factories/GZipFactory.cs +++ b/src/SharpCompress/Factories/GZipFactory.cs @@ -83,20 +83,20 @@ public class GZipFactory { reader = null; - long pos = ((IStreamStack)rewindableStream).GetPosition(); + long pos = rewindableStream.GetPosition(); if (GZipArchive.IsGZipFile(rewindableStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); var testStream = new GZipStream(rewindableStream, CompressionMode.Decompress); if (TarArchive.IsTarFile(testStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); reader = new TarReader(rewindableStream, options, CompressionType.GZip); return true; } - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); reader = OpenReader(rewindableStream, options); return true; } diff --git a/src/SharpCompress/Factories/TarFactory.cs b/src/SharpCompress/Factories/TarFactory.cs index d32020fd..8521f9aa 100644 --- a/src/SharpCompress/Factories/TarFactory.cs +++ b/src/SharpCompress/Factories/TarFactory.cs @@ -166,7 +166,7 @@ public class TarFactory ) { reader = null; - long pos = ((IStreamStack)rewindableStream).GetPosition(); + long pos = rewindableStream.GetPosition(); TestOption? testedOption = null; if (!string.IsNullOrWhiteSpace(options.ExtensionHint)) { @@ -192,7 +192,7 @@ public class TarFactory { continue; // Already tested above } - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); reader = TryOption(rewindableStream, options, pos, testOption); if (reader != null) { @@ -212,17 +212,16 @@ public class TarFactory { if (testOption.CanHandle(rewindableStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); - var inStream = rewindableStream; + rewindableStream.StackSeek(pos); if (testOption.WrapInSharpCompressStream) { - inStream = SharpCompressStream.Create(rewindableStream, leaveOpen: true); + rewindableStream = SharpCompressStream.Create(rewindableStream, leaveOpen: true); } var testStream = testOption.CreateStream(rewindableStream); if (TarArchive.IsTarFile(testStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); return new TarReader(rewindableStream, options, testOption.Type); } } diff --git a/src/SharpCompress/IO/DataDescriptorStream.cs b/src/SharpCompress/IO/DataDescriptorStream.cs index dd589473..31b7d3b8 100644 --- a/src/SharpCompress/IO/DataDescriptorStream.cs +++ b/src/SharpCompress/IO/DataDescriptorStream.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text; namespace SharpCompress.IO; @@ -83,7 +84,7 @@ public class DataDescriptorStream : Stream, IStreamStack private bool validate_data_descriptor(Stream stream, long size) { - var br = new BinaryReader(stream); + using var br = new BinaryReader(stream, Encoding.UTF8, true); br.ReadUInt32(); br.ReadUInt32(); // CRC32 can be checked if we calculate it var compressedSize = br.ReadUInt32(); diff --git a/src/SharpCompress/IO/SharpCompressStream.cs b/src/SharpCompress/IO/SharpCompressStream.cs index ea9bf022..b9e6dc65 100644 --- a/src/SharpCompress/IO/SharpCompressStream.cs +++ b/src/SharpCompress/IO/SharpCompressStream.cs @@ -264,7 +264,6 @@ public class SharpCompressStream : Stream, IStreamStack ValidateBufferState(); } - long orig = _internalPosition; long targetPos; // Calculate the absolute target position based on origin switch (origin) diff --git a/src/SharpCompress/Readers/IReaderExtractionListener.cs b/src/SharpCompress/Readers/IReaderExtractionListener.cs index 49e5dae4..387675f7 100644 --- a/src/SharpCompress/Readers/IReaderExtractionListener.cs +++ b/src/SharpCompress/Readers/IReaderExtractionListener.cs @@ -4,5 +4,7 @@ namespace SharpCompress.Readers; public interface IReaderExtractionListener : IExtractionListener { - void FireEntryExtractionProgress(Entry entry, long sizeTransferred, int iterations); +#pragma warning disable CA1030 + void FireEntryExtractionProgress(Entry entry, long sizeTransferred, int iterations); +#pragma warning restore CA1030 } diff --git a/src/SharpCompress/Readers/ReaderFactory.cs b/src/SharpCompress/Readers/ReaderFactory.cs index fb133d98..0bbd334b 100644 --- a/src/SharpCompress/Readers/ReaderFactory.cs +++ b/src/SharpCompress/Readers/ReaderFactory.cs @@ -22,17 +22,15 @@ public static class ReaderFactory var bStream = new SharpCompressStream(stream, bufferSize: options.BufferSize); - long pos = ((IStreamStack)bStream).GetPosition(); - - var factories = Factories.Factory.Factories.OfType(); + long pos = bStream.GetPosition(); Factory? testedFactory = null; if (!string.IsNullOrWhiteSpace(options.ExtensionHint)) { - testedFactory = factories.FirstOrDefault(a => - a.GetSupportedExtensions() - .Contains(options.ExtensionHint, StringComparer.CurrentCultureIgnoreCase) + testedFactory = Factory.Factories.OfType().FirstOrDefault(a => + a.GetSupportedExtensions() + .Contains(options.ExtensionHint, StringComparer.CurrentCultureIgnoreCase) ); if ( testedFactory?.TryOpenReader(bStream, options, out var reader) == true @@ -41,16 +39,16 @@ public static class ReaderFactory { return reader; } - ((IStreamStack)bStream).StackSeek(pos); + bStream.StackSeek(pos); } - foreach (var factory in factories) + foreach (var factory in Factory.Factories.OfType()) { if (testedFactory == factory) { continue; // Already tested above } - ((IStreamStack)bStream).StackSeek(pos); + bStream.StackSeek(pos); if (factory.TryOpenReader(bStream, options, out var reader) && reader != null) { return reader; diff --git a/src/SharpCompress/Readers/Tar/TarReader.cs b/src/SharpCompress/Readers/Tar/TarReader.cs index aaa0005c..dab091bb 100644 --- a/src/SharpCompress/Readers/Tar/TarReader.cs +++ b/src/SharpCompress/Readers/Tar/TarReader.cs @@ -56,62 +56,62 @@ public class TarReader : AbstractReader public static TarReader Open(Stream stream, ReaderOptions? options = null) { stream.CheckNotNull(nameof(stream)); - options = options ?? new ReaderOptions(); + options ??= new ReaderOptions(); var rewindableStream = new SharpCompressStream(stream); - long pos = ((IStreamStack)rewindableStream).GetPosition(); + long pos = rewindableStream.GetPosition(); if (GZipArchive.IsGZipFile(rewindableStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); var testStream = new GZipStream(rewindableStream, CompressionMode.Decompress); if (TarArchive.IsTarFile(testStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); return new TarReader(rewindableStream, options, CompressionType.GZip); } throw new InvalidFormatException("Not a tar file."); } - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); if (BZip2Stream.IsBZip2(rewindableStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); var testStream = new BZip2Stream(rewindableStream, CompressionMode.Decompress, false); if (TarArchive.IsTarFile(testStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); return new TarReader(rewindableStream, options, CompressionType.BZip2); } throw new InvalidFormatException("Not a tar file."); } - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); if (ZStandardStream.IsZStandard(rewindableStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); var testStream = new ZStandardStream(rewindableStream); if (TarArchive.IsTarFile(testStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); return new TarReader(rewindableStream, options, CompressionType.ZStandard); } throw new InvalidFormatException("Not a tar file."); } - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); if (LZipStream.IsLZipFile(rewindableStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); var testStream = new LZipStream(rewindableStream, CompressionMode.Decompress); if (TarArchive.IsTarFile(testStream)) { - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); return new TarReader(rewindableStream, options, CompressionType.LZip); } throw new InvalidFormatException("Not a tar file."); } - ((IStreamStack)rewindableStream).StackSeek(pos); + rewindableStream.StackSeek(pos); return new TarReader(rewindableStream, options, CompressionType.None); }