Add single-stream constructor to ROCS

This commit is contained in:
Matt Nadareski
2024-04-16 20:02:54 -04:00
parent ce521d92ca
commit ecaec1d44a
2 changed files with 25 additions and 0 deletions

View File

@@ -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()
{

View File

@@ -69,6 +69,23 @@ namespace SabreTools.IO.Streams
_position = 0;
}
/// <summary>
/// Create a new ReadOnlyCompositeStream from a single Stream
/// </summary>
/// <param name="stream"></param>
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;
}
/// <summary>
/// Create a new ReadOnlyCompositeStream from an existing collection of Streams
/// </summary>