Dispose the streams of a ReadOnlyCompositeStream (#6)

Disposing a ReadOnlyCompositeStream did not dispose the streams it
reads from, so files opened only for the composite stayed open until
their streams were finalized. WiseOverlayHeader.OpenFile in
SabreTools.Serialization opens a Wise installer and all of its parts
this way.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gmipf
2026-10-19 15:40:57 +02:00
committed by GitHub
parent 19d73bd170
commit 840b7e2d8a
2 changed files with 32 additions and 0 deletions

View File

@@ -158,6 +158,24 @@ namespace SabreTools.IO.Test
#endregion
#region Dispose
[Fact]
public void Dispose_DisposesStreams()
{
var first = new MemoryStream(new byte[128]);
var second = new MemoryStream(new byte[128]);
var stream = new ReadOnlyCompositeStream(first);
stream.AddStream(second);
stream.Dispose();
Assert.False(first.CanRead);
Assert.False(second.CanRead);
}
#endregion
#region Unimplemented
[Fact]

View File

@@ -163,6 +163,20 @@ namespace SabreTools.IO
#region Stream Implementations
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
if (disposing)
{
foreach (var stream in _streams)
{
stream.Dispose();
}
}
base.Dispose(disposing);
}
/// <inheritdoc/>
public override void Flush()
=> throw new NotImplementedException();