diff --git a/SabreTools.IO.Test/ReadOnlyCompositeStreamTests.cs b/SabreTools.IO.Test/ReadOnlyCompositeStreamTests.cs index aa607c9..2454f9b 100644 --- a/SabreTools.IO.Test/ReadOnlyCompositeStreamTests.cs +++ b/SabreTools.IO.Test/ReadOnlyCompositeStreamTests.cs @@ -35,6 +35,14 @@ namespace SabreTools.IO.Test Assert.Equal(0, stream.Position); } + [Fact] + public void SingleStreamConstructorTest() + { + var stream = new ReadOnlyCompositeStream(new MemoryStream(new byte[1024])); + Assert.Equal(1024, stream.Length); + Assert.Equal(0, stream.Position); + } + [Fact] public void FilledArrayConstructorTest() { diff --git a/SabreTools.IO/Streams/ReadOnlyCompositeStream.cs b/SabreTools.IO/Streams/ReadOnlyCompositeStream.cs index aa5546b..0063975 100644 --- a/SabreTools.IO/Streams/ReadOnlyCompositeStream.cs +++ b/SabreTools.IO/Streams/ReadOnlyCompositeStream.cs @@ -69,6 +69,23 @@ namespace SabreTools.IO.Streams _position = 0; } + /// + /// Create a new ReadOnlyCompositeStream from a single Stream + /// + /// + public ReadOnlyCompositeStream(Stream stream) + { + _streams = [stream]; + _length = 0; + _position = 0; + + // Verify the stream and add to the length + if (!stream.CanRead || !stream.CanSeek) + throw new ArgumentException($"{nameof(stream)} needs to be readable and seekable"); + + _length += stream.Length; + } + /// /// Create a new ReadOnlyCompositeStream from an existing collection of Streams ///