mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-10-02 19:58:45 +00:00
59 lines
1.3 KiB
C#
59 lines
1.3 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.IO;
|
||
|
|
using System.Linq;
|
||
|
|
|
||
|
|
namespace SharpCompress;
|
||
|
|
|
||
|
|
internal static class StreamValidationExtensions
|
||
|
|
{
|
||
|
|
internal static Stream RequireReadable(this Stream stream)
|
||
|
|
{
|
||
|
|
stream.NotNull(nameof(stream));
|
||
|
|
|
||
|
|
if (!stream.CanRead)
|
||
|
|
{
|
||
|
|
throw new ArgumentException("Stream must be readable", nameof(stream));
|
||
|
|
}
|
||
|
|
|
||
|
|
return stream;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal static Stream RequireSeekable(this Stream stream)
|
||
|
|
{
|
||
|
|
stream.NotNull(nameof(stream));
|
||
|
|
|
||
|
|
if (!stream.CanSeek)
|
||
|
|
{
|
||
|
|
throw new ArgumentException("Stream must be seekable", nameof(stream));
|
||
|
|
}
|
||
|
|
|
||
|
|
return stream;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal static IReadOnlyList<Stream> RequireSeekable(this IReadOnlyList<Stream> streams)
|
||
|
|
{
|
||
|
|
streams.NotNull(nameof(streams));
|
||
|
|
|
||
|
|
foreach (var stream in streams)
|
||
|
|
{
|
||
|
|
stream.RequireSeekable();
|
||
|
|
}
|
||
|
|
|
||
|
|
return streams;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal static IReadOnlyList<Stream> RequireReadable(this IEnumerable<Stream> streams)
|
||
|
|
{
|
||
|
|
streams.NotNull(nameof(streams));
|
||
|
|
|
||
|
|
var streamArray = streams as IReadOnlyList<Stream> ?? streams.ToArray();
|
||
|
|
foreach (var stream in streamArray)
|
||
|
|
{
|
||
|
|
stream.RequireReadable();
|
||
|
|
}
|
||
|
|
|
||
|
|
return streamArray;
|
||
|
|
}
|
||
|
|
}
|