mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-23 07:25:11 +00:00
use more specifc interface for sevenzip
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user