Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public virtual Stream OpenEntryStream()
return Parts.Single().GetCompressedStream().NotNull();
}

public async ValueTask<Stream> OpenEntryStreamAsync(
public virtual async ValueTask<Stream> OpenEntryStreamAsync(
CancellationToken cancellationToken = default
)
{
Expand Down
10 changes: 10 additions & 0 deletions src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Common;
using SharpCompress.IO;

Expand Down Expand Up @@ -61,6 +63,14 @@ public override Stream OpenEntryStream()
return SharpCompressStream.CreateNonDisposing(stream);
}

public override ValueTask<Stream> OpenEntryStreamAsync(
CancellationToken cancellationToken = default
)
{
cancellationToken.ThrowIfCancellationRequested();
return new(OpenEntryStream());
}

internal override void Close()
{
if (closeStream)
Expand Down
35 changes: 35 additions & 0 deletions tests/SharpCompress.Test/GZip/GZipArchiveAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using SharpCompress.Archives.GZip;
using SharpCompress.Archives.Tar;
using SharpCompress.Common;
using SharpCompress.Compressors.Deflate;
using SharpCompress.Readers;
using SharpCompress.Test.Mocks;
using SharpCompress.Writers.GZip;
using Xunit;
Expand Down Expand Up @@ -181,4 +183,37 @@ public async Task TestGzArchiveTypeGzip_Async()
await using var archive = await GZipArchive.OpenAsyncArchive(new AsyncOnlyStream(stream));
Assert.Equal(archive.Type, ArchiveType.GZip);
}

[Fact]
public async ValueTask GZip_Create_New_Async()
{
var scratchPath = Path.Combine(SCRATCH_FILES_PATH, Guid.NewGuid().ToString());
var filePath = Path.Combine(scratchPath, "test.gz");
if (!Directory.Exists(scratchPath))
{
Directory.CreateDirectory(scratchPath);
}
await using (var archive = (GZipArchive)await GZipArchive.CreateAsyncArchive())
{
await archive.AddEntryAsync("Tar.tar", Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar"));
await archive.SaveToAsync(filePath, new GZipWriterOptions(CompressionLevel.BestSpeed));
}
Comment thread
adamhathcock marked this conversation as resolved.
var scratchPath2 = Path.Combine(SCRATCH_FILES_PATH, Guid.NewGuid().ToString());
if (!Directory.Exists(scratchPath2))
{
Directory.CreateDirectory(scratchPath2);
}
Comment thread
adamhathcock marked this conversation as resolved.

await using var archive2 = await GZipArchive.OpenAsyncArchive(
new AsyncOnlyStream(File.OpenRead(filePath))
Comment thread
adamhathcock marked this conversation as resolved.
Outdated
);
await foreach (var entry in archive2.EntriesAsync)
{
await entry.WriteToDirectoryAsync(scratchPath2);
}
CompareFilesByPath(
Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar"),
Path.Combine(scratchPath2, "Tar.tar")
);
}
}
Loading