mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-07-08 18:16:30 +00:00
Fix writable archive async disposal and add regression tests
This commit is contained in:
committed by
GitHub
parent
76ed18fc76
commit
5adae487c7
@@ -122,6 +122,14 @@ public abstract partial class AbstractWritableArchive<TEntry, TVolume, TOptions>
|
||||
.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,
|
||||
|
||||
@@ -286,9 +286,9 @@
|
||||
"net10.0": {
|
||||
"Microsoft.NET.ILLink.Tasks": {
|
||||
"type": "Direct",
|
||||
"requested": "[10.0.8, )",
|
||||
"resolved": "10.0.8",
|
||||
"contentHash": "dVbSXGIFNR5nZcv2tOLoWI+a9T4jtFd77IYjuND+QVe360qWgAF7H0WtoopYhRw/+SgpGUTyrkrh+65+ClNnfw=="
|
||||
"requested": "[10.0.0, )",
|
||||
"resolved": "10.0.0",
|
||||
"contentHash": "kICGrGYEzCNI3wPzfEXcwNHgTvlvVn9yJDhSdRK+oZQy4jvYH529u7O0xf5ocQKzOMjfS07+3z9PKRIjrFMJDA=="
|
||||
},
|
||||
"Microsoft.NETFramework.ReferenceAssemblies": {
|
||||
"type": "Direct",
|
||||
@@ -388,9 +388,9 @@
|
||||
"net8.0": {
|
||||
"Microsoft.NET.ILLink.Tasks": {
|
||||
"type": "Direct",
|
||||
"requested": "[8.0.27, )",
|
||||
"resolved": "8.0.27",
|
||||
"contentHash": "rQi9TxifHRnXP7lVRZH05DxD2/XGbJp12q0ozcbrlBlBnyyzssFTH/2vLhtKWUp2CT1qVscTrcYTFiwTyKPKRg=="
|
||||
"requested": "[8.0.22, )",
|
||||
"resolved": "8.0.22",
|
||||
"contentHash": "MhcMithKEiyyNkD2ZfbDZPmcOdi0GheGfg8saEIIEfD/fol3iHmcV8TsZkD4ZYz5gdUuoX4YtlVySUU7Sxl9SQ=="
|
||||
},
|
||||
"Microsoft.NETFramework.ReferenceAssemblies": {
|
||||
"type": "Direct",
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
"net10.0": {
|
||||
"Microsoft.DotNet.ILCompiler": {
|
||||
"type": "Direct",
|
||||
"requested": "[10.0.6, )",
|
||||
"resolved": "10.0.6",
|
||||
"contentHash": "nBOzxOys8OeyJ+Nsi/uYlI/5TSsvwjaM/p5m4dTL6khCLx9UuP3b2ec3HeuBw/+F7hHCAZG1yFx8VBeoRAX+EQ=="
|
||||
"requested": "[10.0.0, )",
|
||||
"resolved": "10.0.0",
|
||||
"contentHash": "f9u8fMRROe2lS5MOOLutK6iSNTK9pC3kqd90FIn8Sk29fbZ0QDjZrBbwUkhouk/8dppC71SIEQaag0lGRTxvfA=="
|
||||
},
|
||||
"Microsoft.NET.ILLink.Tasks": {
|
||||
"type": "Direct",
|
||||
"requested": "[10.0.6, )",
|
||||
"resolved": "10.0.6",
|
||||
"contentHash": "QKuvS0LWX4fjFqeDkyM7Kqt8P3wYTiPD4nwU+9y59n0sCiG714fxDgbbN82vDnzq89AF/PiHl92TP2C4aFDUQA=="
|
||||
"requested": "[10.0.0, )",
|
||||
"resolved": "10.0.0",
|
||||
"contentHash": "kICGrGYEzCNI3wPzfEXcwNHgTvlvVn9yJDhSdRK+oZQy4jvYH529u7O0xf5ocQKzOMjfS07+3z9PKRIjrFMJDA=="
|
||||
},
|
||||
"Microsoft.NETFramework.ReferenceAssemblies": {
|
||||
"type": "Direct",
|
||||
@@ -63,22 +63,6 @@
|
||||
"sharpcompress": {
|
||||
"type": "Project"
|
||||
}
|
||||
},
|
||||
"net10.0/osx-arm64": {
|
||||
"Microsoft.DotNet.ILCompiler": {
|
||||
"type": "Direct",
|
||||
"requested": "[10.0.6, )",
|
||||
"resolved": "10.0.6",
|
||||
"contentHash": "nBOzxOys8OeyJ+Nsi/uYlI/5TSsvwjaM/p5m4dTL6khCLx9UuP3b2ec3HeuBw/+F7hHCAZG1yFx8VBeoRAX+EQ==",
|
||||
"dependencies": {
|
||||
"runtime.osx-arm64.Microsoft.DotNet.ILCompiler": "10.0.6"
|
||||
}
|
||||
},
|
||||
"runtime.osx-arm64.Microsoft.DotNet.ILCompiler": {
|
||||
"type": "Transitive",
|
||||
"resolved": "10.0.6",
|
||||
"contentHash": "+yovwOAlIpfIcH+ZWmLYXWTSWYJ93wcQxF/RVk+X4MXgLASeosCJYVLqP20g0cufKjoRqvCmnklR6y9Su3ORtA=="
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,4 +221,23 @@ public class GZipArchiveAsyncTests : ArchiveTests
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +179,28 @@ public class TarArchiveAsyncTests : ArchiveTests
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -186,6 +186,28 @@ public class ZipArchiveAsyncTests : ArchiveTests
|
||||
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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user