Files
sharpcompress/src/SharpCompress/StreamValidationExtensions.cs

57 lines
1.3 KiB
C#
Raw Normal View History

2026-04-23 10:11:54 +01:00
using System;
using System.Collections.Generic;
using System.IO;
namespace SharpCompress;
internal static class StreamValidationExtensions
{
2026-04-23 11:43:10 +01:00
internal static void RequireReadable(this Stream stream)
2026-04-23 10:11:54 +01:00
{
stream.NotNull(nameof(stream));
if (!stream.CanRead)
{
throw new ArgumentException("Stream must be readable", nameof(stream));
}
}
2026-04-23 11:43:10 +01:00
internal static void RequireSeekable(this Stream stream)
2026-04-23 10:11:54 +01:00
{
stream.NotNull(nameof(stream));
if (!stream.CanSeek)
{
throw new ArgumentException("Stream must be seekable", nameof(stream));
}
}
2026-04-23 11:43:10 +01:00
internal static void RequireWritable(this Stream stream)
2026-04-23 11:19:09 +01:00
{
stream.NotNull(nameof(stream));
if (!stream.CanWrite)
{
throw new ArgumentException("Stream must be writable", nameof(stream));
}
}
2026-04-23 11:43:10 +01:00
internal static IEnumerable<Stream> RequireSeekable(this IEnumerable<Stream> streams)
2026-04-23 10:11:54 +01:00
{
foreach (var stream in streams)
{
stream.RequireSeekable();
2026-04-23 11:43:10 +01:00
yield return stream;
2026-04-23 10:11:54 +01:00
}
}
2026-04-23 11:43:10 +01:00
internal static IEnumerable<Stream> RequireReadable(this IEnumerable<Stream> streams)
2026-04-23 10:11:54 +01:00
{
2026-04-23 11:43:10 +01:00
foreach (var stream in streams)
2026-04-23 10:11:54 +01:00
{
stream.RequireReadable();
2026-04-23 11:43:10 +01:00
yield return stream;
2026-04-23 10:11:54 +01:00
}
}
}