mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-25 00:15:15 +00:00
add seekable checks
This commit is contained in:
@@ -99,6 +99,8 @@ public static partial class ArchiveFactory
|
||||
throw new ArchiveOperationException("No streams");
|
||||
}
|
||||
|
||||
EnsureSeekable(streamsArray);
|
||||
|
||||
var firstStream = streamsArray[0];
|
||||
if (streamsArray.Count == 1)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,22 @@ namespace SharpCompress.Archives;
|
||||
|
||||
public static partial class ArchiveFactory
|
||||
{
|
||||
internal static void EnsureSeekable(Stream stream)
|
||||
{
|
||||
if (stream is null || !stream.CanSeek)
|
||||
{
|
||||
throw new ArgumentException("Stream must be seekable", nameof(stream));
|
||||
}
|
||||
}
|
||||
|
||||
internal static void EnsureSeekable(IReadOnlyList<Stream> streams)
|
||||
{
|
||||
foreach (var stream in streams)
|
||||
{
|
||||
EnsureSeekable(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static IArchive OpenArchive(Stream stream, ReaderOptions? readerOptions = null)
|
||||
{
|
||||
readerOptions ??= ReaderOptions.ForExternalStream;
|
||||
@@ -80,6 +96,8 @@ public static partial class ArchiveFactory
|
||||
throw new ArchiveOperationException("No streams");
|
||||
}
|
||||
|
||||
EnsureSeekable(streamsArray);
|
||||
|
||||
var firstStream = streamsArray[0];
|
||||
if (streamsArray.Count == 1)
|
||||
{
|
||||
|
||||
@@ -77,6 +77,7 @@ public partial class GZipArchive
|
||||
)
|
||||
{
|
||||
streams.NotNull(nameof(streams));
|
||||
SharpCompress.Archives.ArchiveFactory.EnsureSeekable(streams);
|
||||
var strms = streams;
|
||||
return new GZipArchive(
|
||||
new SourceStream(
|
||||
|
||||
@@ -92,6 +92,7 @@ public partial class RarArchive
|
||||
)
|
||||
{
|
||||
streams.NotNull(nameof(streams));
|
||||
SharpCompress.Archives.ArchiveFactory.EnsureSeekable(streams);
|
||||
var strms = streams;
|
||||
return new RarArchive(
|
||||
new SourceStream(
|
||||
|
||||
@@ -72,6 +72,7 @@ public partial class SevenZipArchive
|
||||
)
|
||||
{
|
||||
streams.NotNull(nameof(streams));
|
||||
SharpCompress.Archives.ArchiveFactory.EnsureSeekable(streams);
|
||||
var strms = streams;
|
||||
return new SevenZipArchive(
|
||||
new SourceStream(
|
||||
|
||||
@@ -67,6 +67,7 @@ public partial class TarArchive
|
||||
)
|
||||
{
|
||||
streams.NotNull(nameof(streams));
|
||||
SharpCompress.Archives.ArchiveFactory.EnsureSeekable(streams);
|
||||
var strms = streams;
|
||||
var sourceStream = new SourceStream(
|
||||
strms[0],
|
||||
@@ -103,6 +104,10 @@ public partial class TarArchive
|
||||
)
|
||||
{
|
||||
stream.NotNull(nameof(stream));
|
||||
if (!stream.CanSeek)
|
||||
{
|
||||
throw new ArgumentException("Stream must be seekable", nameof(stream));
|
||||
}
|
||||
var sourceStream = new SourceStream(
|
||||
stream,
|
||||
i => null,
|
||||
@@ -159,6 +164,7 @@ public partial class TarArchive
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
streams.NotNull(nameof(streams));
|
||||
SharpCompress.Archives.ArchiveFactory.EnsureSeekable(streams);
|
||||
var strms = streams;
|
||||
var sourceStream = new SourceStream(
|
||||
strms[0],
|
||||
|
||||
@@ -68,6 +68,7 @@ public partial class ZipArchive
|
||||
)
|
||||
{
|
||||
streams.NotNull(nameof(streams));
|
||||
SharpCompress.Archives.ArchiveFactory.EnsureSeekable(streams);
|
||||
var strms = streams;
|
||||
return new ZipArchive(
|
||||
new SourceStream(
|
||||
@@ -132,6 +133,7 @@ public partial class ZipArchive
|
||||
)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
SharpCompress.Archives.ArchiveFactory.EnsureSeekable(streams);
|
||||
return new((IWritableAsyncArchive<ZipWriterOptions>)OpenArchive(streams, readerOptions));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user