Address code review feedback for ACE archive support

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-29 13:32:01 +00:00
parent 6ae63f6a47
commit c783a83a9c
2 changed files with 26 additions and 27 deletions

View File

@@ -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;

View File

@@ -13,14 +13,14 @@ namespace SharpCompress.Readers.Ace;
/// </summary>
public class AceReader : AbstractReader<AceEntry, AceVolume>
{
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<AceEntry, AceVolume>
// 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));
}