mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
gzipwriter async
This commit is contained in:
@@ -8,30 +8,18 @@ namespace SharpCompress.Writers;
|
||||
|
||||
public abstract partial class AbstractWriter
|
||||
{
|
||||
public virtual async ValueTask WriteAsync(
|
||||
public abstract ValueTask WriteAsync(
|
||||
string filename,
|
||||
Stream source,
|
||||
DateTime? modificationTime,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
// Default implementation calls synchronous version
|
||||
// Derived classes should override for true async behavior
|
||||
Write(filename, source, modificationTime);
|
||||
await Task.CompletedTask.ConfigureAwait(false);
|
||||
}
|
||||
);
|
||||
|
||||
public virtual async ValueTask WriteDirectoryAsync(
|
||||
public abstract ValueTask WriteDirectoryAsync(
|
||||
string directoryName,
|
||||
DateTime? modificationTime,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
// Default implementation calls synchronous version
|
||||
// Derived classes should override for true async behavior
|
||||
WriteDirectory(directoryName, modificationTime);
|
||||
await Task.CompletedTask.ConfigureAwait(false);
|
||||
}
|
||||
);
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
|
||||
31
src/SharpCompress/Writers/GZip/GZipWriter.Async.cs
Normal file
31
src/SharpCompress/Writers/GZip/GZipWriter.Async.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Compressors.Deflate;
|
||||
|
||||
namespace SharpCompress.Writers.GZip;
|
||||
|
||||
public partial class GZipWriter
|
||||
{
|
||||
public override async ValueTask WriteAsync(string filename, Stream source, DateTime? modificationTime, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_wroteToStream)
|
||||
{
|
||||
throw new ArgumentException("Can only write a single stream to a GZip file.");
|
||||
}
|
||||
var stream = (GZipStream)OutputStream;
|
||||
stream.FileName = filename;
|
||||
stream.LastModified = modificationTime;
|
||||
var progressStream = WrapWithProgress(source, filename);
|
||||
#if LEGACY_DOTNET
|
||||
await progressStream.CopyToAsync(stream);
|
||||
#else
|
||||
await progressStream.CopyToAsync(stream, cancellationToken);
|
||||
#endif
|
||||
_wroteToStream = true;
|
||||
}
|
||||
|
||||
public override ValueTask WriteDirectoryAsync(string directoryName, DateTime? modificationTime, CancellationToken cancellationToken = default) =>
|
||||
throw new NotSupportedException("GZip archives do not support directory entries.");
|
||||
}
|
||||
Reference in New Issue
Block a user