Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/SharpCompress/Archives/AbstractWritableArchive.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ await SaveToAsync(stream, options, OldEntriesAsync, newEntries, cancellationToke
.ConfigureAwait(false);
}

public override async ValueTask DisposeAsync()
{
await base.DisposeAsync().ConfigureAwait(false);
newEntries.Cast<Entry>().ForEach(x => x.Close());
removedEntries.Cast<Entry>().ForEach(x => x.Close());
modifiedEntries.Cast<Entry>().ForEach(x => x.Close());
}

protected abstract ValueTask SaveToAsync(
Stream stream,
TOptions options,
Expand Down
19 changes: 19 additions & 0 deletions tests/SharpCompress.Test/GZip/GZipArchiveAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,23 @@ public async ValueTask GZip_Create_New_Async()
Path.Combine(scratchPath2, "Tar.tar")
);
}

[Fact]
public async ValueTask GZip_Async_Dispose_Closes_New_Entry_Stream()
{
var entryStream = new TestStream(new MemoryStream(new byte[] { 1, 2, 3 }));

await using (var archive = await GZipArchive.CreateAsyncArchive())
{
await archive.AddEntryAsync(
"test.bin",
entryStream,
closeStream: true,
size: entryStream.Length
);
await archive.SaveToAsync(new MemoryStream(), new GZipWriterOptions());
}

Assert.True(entryStream.IsDisposed);
}
}
22 changes: 22 additions & 0 deletions tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@ public async ValueTask Tar_Create_New_Async()
CompareArchivesByPath(unmodified, scratchPath);
}

[Fact]
public async ValueTask Tar_Async_Dispose_Closes_New_Entry_Stream()
{
var entryStream = new TestStream(new MemoryStream(Encoding.UTF8.GetBytes("test")));

await using (var archive = await TarArchive.CreateAsyncArchive())
{
await archive.AddEntryAsync(
"test.txt",
entryStream,
closeStream: true,
size: entryStream.Length
);
await archive.SaveToAsync(
new MemoryStream(),
new TarWriterOptions(CompressionType.None, true)
);
}

Assert.True(entryStream.IsDisposed);
}

[Fact]
public async ValueTask Tar_Random_Write_Add_Async()
{
Expand Down
22 changes: 22 additions & 0 deletions tests/SharpCompress.Test/Zip/ZipArchiveAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,28 @@ public async ValueTask Zip_Create_New_Async()
CompareArchivesByPath(unmodified, scratchPath);
}

[Fact]
public async ValueTask Zip_Async_Dispose_Closes_New_Entry_Stream()
{
var entryStream = new TestStream(new MemoryStream(Encoding.UTF8.GetBytes("test")));

await using (var archive = await ZipArchive.CreateAsyncArchive())
{
await archive.AddEntryAsync(
"test.txt",
entryStream,
closeStream: true,
size: entryStream.Length
);
await archive.SaveToAsync(
new MemoryStream(),
new ZipWriterOptions(CompressionType.Deflate)
);
}

Assert.True(entryStream.IsDisposed);
}

[Fact]
public async ValueTask Zip_Deflate_Entry_Stream_Async()
{
Expand Down
Loading