From 8aa1f58af5b98647d0f97bfda4d745f38616206d Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 8 Feb 2021 20:57:21 -0500 Subject: [PATCH] Delete dead IFileFormatReader code in System.IO.Compression (#47408) --- .../src/System.IO.Compression.csproj | 1 - .../DeflateManaged/DeflateManagedStream.cs | 2 +- .../IO/Compression/DeflateManaged/FileFormats.cs | 13 ----- .../Compression/DeflateManaged/InflaterManaged.cs | 62 ++-------------------- 4 files changed, 4 insertions(+), 74 deletions(-) delete mode 100644 src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/FileFormats.cs diff --git a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj index df5985b..e2a7ade 100644 --- a/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj +++ b/src/libraries/System.IO.Compression/src/System.IO.Compression.csproj @@ -15,7 +15,6 @@ - diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/DeflateManagedStream.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/DeflateManagedStream.cs index a584771..2d39852 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/DeflateManagedStream.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/DeflateManagedStream.cs @@ -31,7 +31,7 @@ namespace System.IO.Compression Debug.Assert(method == ZipArchiveEntry.CompressionMethodValues.Deflate64); - _inflater = new InflaterManaged(null, method == ZipArchiveEntry.CompressionMethodValues.Deflate64 ? true : false, uncompressedSize); + _inflater = new InflaterManaged(method == ZipArchiveEntry.CompressionMethodValues.Deflate64, uncompressedSize); _stream = stream; _buffer = new byte[DefaultBufferSize]; diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/FileFormats.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/FileFormats.cs deleted file mode 100644 index ee38217..0000000 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/FileFormats.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace System.IO.Compression -{ - internal interface IFileFormatReader - { - bool ReadHeader(InputBuffer input); - bool ReadFooter(InputBuffer input); - void UpdateWithBytesRead(byte[] buffer, int offset, int bytesToCopy); - void Validate(); - } -} diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/InflaterManaged.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/InflaterManaged.cs index 4f1c368..7fe90bb 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/InflaterManaged.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateManaged/InflaterManaged.cs @@ -48,7 +48,6 @@ namespace System.IO.Compression private HuffmanTree? _distanceTree; private InflaterState _state; - private readonly bool _hasFormatReader; private int _bfinal; private BlockType _blockType; @@ -75,9 +74,7 @@ namespace System.IO.Compression private readonly long _uncompressedSize; private long _currentInflatedCount; - private readonly IFileFormatReader? _formatReader; // class to decode header and footer (e.g. gzip) - - internal InflaterManaged(IFileFormatReader? reader, bool deflate64, long uncompressedSize) + internal InflaterManaged(bool deflate64, long uncompressedSize) { _output = new OutputWindow(); _input = new InputBuffer(); @@ -86,19 +83,7 @@ namespace System.IO.Compression _codeLengthTreeCodeLength = new byte[HuffmanTree.NumberOfCodeLengthTreeElements]; _deflate64 = deflate64; _uncompressedSize = uncompressedSize; - if (reader != null) - { - _formatReader = reader; - _hasFormatReader = true; - } - Reset(); - } - - private void Reset() - { - _state = _hasFormatReader ? - InflaterState.ReadingHeader : // start by reading Header info - InflaterState.ReadingBFinal; // start by reading BFinal bit + _state = InflaterState.ReadingBFinal; // start by reading BFinal bit } public void SetInput(byte[] inputBytes, int offset, int length) => @@ -137,12 +122,6 @@ namespace System.IO.Compression } if (copied > 0) { - if (_hasFormatReader) - { - Debug.Assert(_formatReader != null); - _formatReader.UpdateWithBytesRead(bytes, offset, copied); - } - offset += copied; count += copied; length -= copied; @@ -155,17 +134,6 @@ namespace System.IO.Compression // Decode will return false when more input is needed } while (!Finished() && Decode()); - if (_state == InflaterState.VerifyingFooter) - { // finished reading CRC - // In this case finished is true and output window has all the data. - // But some data in output window might not be copied out. - if (_output.AvailableBytes == 0) - { - Debug.Assert(_formatReader != null); - _formatReader.Validate(); - } - } - return count; } @@ -200,27 +168,6 @@ namespace System.IO.Compression return true; } - if (_hasFormatReader) - { - Debug.Assert(_formatReader != null); - if (_state == InflaterState.ReadingHeader) - { - if (!_formatReader.ReadHeader(_input)) - { - return false; - } - _state = InflaterState.ReadingBFinal; - } - else if (_state == InflaterState.StartReadingFooter || _state == InflaterState.ReadingFooter) - { - if (!_formatReader.ReadFooter(_input)) - return false; - - _state = InflaterState.VerifyingFooter; - return true; - } - } - if (_state == InflaterState.ReadingBFinal) { // reading bfinal bit @@ -293,10 +240,7 @@ namespace System.IO.Compression // if (eob && (_bfinal != 0)) { - if (_hasFormatReader) - _state = InflaterState.StartReadingFooter; - else - _state = InflaterState.Done; + _state = InflaterState.Done; } return result; } -- 2.7.4