mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-11-15 16:41:58 +00:00
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:
@@ -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]
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user