use more specifc interface for sevenzip

This commit is contained in:
Adam Hathcock
2026-02-17 14:02:05 +00:00
parent bdf17bf452
commit 1506f43006
5 changed files with 25 additions and 23 deletions

View File

@@ -12,11 +12,11 @@ namespace SharpCompress.Archives.SevenZip;
public partial class SevenZipArchive
#if NET8_0_OR_GREATER
: IArchiveOpenable<IArchive, IAsyncArchive>,
IMultiArchiveOpenable<IArchive, IAsyncArchive>
: IArchiveOpenable<ISevenZipArchive, ISevenZipAsyncArchive>,
IMultiArchiveOpenable<ISevenZipArchive, ISevenZipAsyncArchive>
#endif
{
public static ValueTask<IAsyncArchive> OpenAsyncArchive(
public static ValueTask<ISevenZipAsyncArchive> OpenAsyncArchive(
string path,
ReaderOptions? readerOptions = null,
CancellationToken cancellationToken = default
@@ -25,17 +25,23 @@ public partial class SevenZipArchive
cancellationToken.ThrowIfCancellationRequested();
path.NotNullOrEmpty("path");
return new(
(IAsyncArchive)OpenArchive(new FileInfo(path), readerOptions ?? new ReaderOptions())
(ISevenZipAsyncArchive)OpenArchive(
new FileInfo(path),
readerOptions ?? new ReaderOptions()
)
);
}
public static IArchive OpenArchive(string filePath, ReaderOptions? readerOptions = null)
public static ISevenZipArchive OpenArchive(string filePath, ReaderOptions? readerOptions = null)
{
filePath.NotNullOrEmpty("filePath");
return OpenArchive(new FileInfo(filePath), readerOptions ?? new ReaderOptions());
}
public static IArchive OpenArchive(FileInfo fileInfo, ReaderOptions? readerOptions = null)
public static ISevenZipArchive OpenArchive(
FileInfo fileInfo,
ReaderOptions? readerOptions = null
)
{
fileInfo.NotNull(nameof(fileInfo));
return new SevenZipArchive(
@@ -47,7 +53,7 @@ public partial class SevenZipArchive
);
}
public static IArchive OpenArchive(
public static ISevenZipArchive OpenArchive(
IEnumerable<FileInfo> fileInfos,
ReaderOptions? readerOptions = null
)
@@ -63,7 +69,7 @@ public partial class SevenZipArchive
);
}
public static IArchive OpenArchive(
public static ISevenZipArchive OpenArchive(
IEnumerable<Stream> streams,
ReaderOptions? readerOptions = null
)
@@ -79,7 +85,7 @@ public partial class SevenZipArchive
);
}
public static IArchive OpenArchive(Stream stream, ReaderOptions? readerOptions = null)
public static ISevenZipArchive OpenArchive(Stream stream, ReaderOptions? readerOptions = null)
{
stream.NotNull(nameof(stream));
@@ -93,44 +99,44 @@ public partial class SevenZipArchive
);
}
public static ValueTask<IAsyncArchive> OpenAsyncArchive(
public static ValueTask<ISevenZipAsyncArchive> OpenAsyncArchive(
Stream stream,
ReaderOptions? readerOptions = null,
CancellationToken cancellationToken = default
)
{
cancellationToken.ThrowIfCancellationRequested();
return new((IAsyncArchive)OpenArchive(stream, readerOptions));
return new((ISevenZipAsyncArchive)OpenArchive(stream, readerOptions));
}
public static ValueTask<IAsyncArchive> OpenAsyncArchive(
public static ValueTask<ISevenZipAsyncArchive> OpenAsyncArchive(
FileInfo fileInfo,
ReaderOptions? readerOptions = null,
CancellationToken cancellationToken = default
)
{
cancellationToken.ThrowIfCancellationRequested();
return new((IAsyncArchive)OpenArchive(fileInfo, readerOptions));
return new((ISevenZipAsyncArchive)OpenArchive(fileInfo, readerOptions));
}
public static ValueTask<IAsyncArchive> OpenAsyncArchive(
public static ValueTask<ISevenZipAsyncArchive> OpenAsyncArchive(
IReadOnlyList<Stream> streams,
ReaderOptions? readerOptions = null,
CancellationToken cancellationToken = default
)
{
cancellationToken.ThrowIfCancellationRequested();
return new((IAsyncArchive)OpenArchive(streams, readerOptions));
return new((ISevenZipAsyncArchive)OpenArchive(streams, readerOptions));
}
public static ValueTask<IAsyncArchive> OpenAsyncArchive(
public static ValueTask<ISevenZipAsyncArchive> OpenAsyncArchive(
IReadOnlyList<FileInfo> fileInfos,
ReaderOptions? readerOptions = null,
CancellationToken cancellationToken = default
)
{
cancellationToken.ThrowIfCancellationRequested();
return new((IAsyncArchive)OpenArchive(fileInfos, readerOptions));
return new((ISevenZipAsyncArchive)OpenArchive(fileInfos, readerOptions));
}
public static bool IsSevenZipFile(string filePath) => IsSevenZipFile(new FileInfo(filePath));

View File

@@ -206,7 +206,7 @@ public class ZipFactory
/// <inheritdoc/>
public IWriter OpenWriter(Stream stream, IWriterOptions writerOptions)
{
ZipWriterOptions zipOptions = writerOptions switch
var zipOptions = writerOptions switch
{
ZipWriterOptions zwo => zwo,
WriterOptions wo => new ZipWriterOptions(wo),

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.IO;
using System.Threading;
@@ -12,8 +11,6 @@ public partial class ZipReader
: IReaderOpenable<IZipReader, IZipAsyncReader>
#endif
{
/// <summary>
/// Opens a ZipReader for Non-seeking usage with a single volume
/// </summary>

View File

@@ -37,7 +37,6 @@ public partial class ZipReader : AbstractReader<ZipEntry, ZipVolume>, IZipReader
public override ZipVolume Volume { get; }
protected override IEnumerable<ZipEntry> GetEntries(Stream stream)
{
foreach (var h in _headerFactory.ReadStreamHeader(stream))

View File

@@ -307,7 +307,7 @@ public class SevenZipArchiveTests : ArchiveTests
using var reader = archive.ExtractAllEntries();
Assert.IsType<ISevenZipReader>(reader);
Assert.IsAssignableFrom<ISevenZipReader>(reader);
SevenZipReader sevenZipReader = (SevenZipReader)reader;
sevenZipReader.DiagnosticsEnabled = true;