From c783a83a9c8a8c174e09faf8a220cb901b4d156f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 29 Nov 2025 13:32:01 +0000 Subject: [PATCH] Address code review feedback for ACE archive support Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- src/SharpCompress/Common/Ace/AceFilePart.cs | 40 ++++++++++----------- src/SharpCompress/Readers/Ace/AceReader.cs | 13 +++---- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/SharpCompress/Common/Ace/AceFilePart.cs b/src/SharpCompress/Common/Ace/AceFilePart.cs index 962d173d..21506be5 100644 --- a/src/SharpCompress/Common/Ace/AceFilePart.cs +++ b/src/SharpCompress/Common/Ace/AceFilePart.cs @@ -24,29 +24,27 @@ public class AceFilePart : FilePart internal override Stream GetCompressedStream() { - if (_stream != null) + if (_stream is null) { - Stream compressedStream; - switch (Header.CompressionMethod) - { - case CompressionType.None: - // Stored - no compression - compressedStream = new ReadOnlySubStream( - _stream, - Header.DataStartPosition, - Header.CompressedSize - ); - break; - default: - // ACE uses proprietary compression methods that are not publicly documented - // For now, we throw an exception for compressed entries - throw new NotSupportedException( - $"ACE compression method '{Header.CompressionMethod}' is not supported. Only stored (uncompressed) entries can be extracted." - ); - } - return compressedStream; + throw new InvalidOperationException("Stream is not available."); + } + + switch (Header.CompressionMethod) + { + case CompressionType.None: + // Stored - no compression + return new ReadOnlySubStream( + _stream, + Header.DataStartPosition, + Header.CompressedSize + ); + default: + // ACE uses proprietary compression methods that are not publicly documented + // For now, we throw an exception for compressed entries + throw new NotSupportedException( + $"ACE compression method '{Header.CompressionMethod}' is not supported. Only stored (uncompressed) entries can be extracted." + ); } - return _stream.NotNull(); } internal override Stream? GetRawStream() => _stream; diff --git a/src/SharpCompress/Readers/Ace/AceReader.cs b/src/SharpCompress/Readers/Ace/AceReader.cs index 3105902b..f64480e8 100644 --- a/src/SharpCompress/Readers/Ace/AceReader.cs +++ b/src/SharpCompress/Readers/Ace/AceReader.cs @@ -13,14 +13,14 @@ namespace SharpCompress.Readers.Ace; /// public class AceReader : AbstractReader { - private readonly AceEntryHeader _headerReader; + private readonly AceEntryHeader _mainHeaderReader; private bool _mainHeaderRead; private AceReader(Stream stream, ReaderOptions options) : base(options, ArchiveType.Ace) { Volume = new AceVolume(stream, options, 0); - _headerReader = new AceEntryHeader(Options.ArchiveEncoding); + _mainHeaderReader = new AceEntryHeader(Options.ArchiveEncoding); } public override AceVolume Volume { get; } @@ -42,17 +42,18 @@ public class AceReader : AbstractReader // First, skip past the main header if we haven't already if (!_mainHeaderRead) { - if (!_headerReader.ReadMainHeader(stream)) + if (!_mainHeaderReader.ReadMainHeader(stream)) { yield break; } _mainHeaderRead = true; } - // Read file entries - AceEntryHeader headerReader = new AceEntryHeader(Options.ArchiveEncoding); + // Read file entries - create new header reader for each entry + // since ReadHeader modifies the object state + AceEntryHeader entryHeaderReader = new AceEntryHeader(Options.ArchiveEncoding); AceEntryHeader? header; - while ((header = headerReader.ReadHeader(stream)) != null) + while ((header = entryHeaderReader.ReadHeader(stream)) != null) { yield return new AceEntry(new AceFilePart(header, stream)); }