add writer support for async

This commit is contained in:
Adam Hathcock
2024-03-12 15:40:29 +00:00
parent ab5535eba3
commit e5944cf72c
6 changed files with 1150 additions and 109 deletions

View File

@@ -2,6 +2,8 @@ using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Readers;
namespace SharpCompress;
@@ -391,4 +393,10 @@ public static class Utility
buffer[offset + 2] = (byte)(number >> 8);
buffer[offset + 3] = (byte)number;
}
public static async ValueTask WriteAsync(
this Stream stream,
byte[] bytes,
CancellationToken cancellationToken
) => await stream.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false);
}

View File

@@ -2,6 +2,8 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Common;
namespace SharpCompress.Writers;
@@ -25,6 +27,16 @@ public abstract class AbstractWriter : IWriter
protected WriterOptions WriterOptions { get; }
public abstract void Write(string filename, Stream source, DateTime? modificationTime);
#if !NETFRAMEWORK && !NETSTANDARD2_0
public abstract ValueTask WriteAsync(
string filename,
Stream source,
DateTime? modificationTime,
CancellationToken cancellationToken
);
public abstract ValueTask DisposeAsync();
#endif
protected virtual void Dispose(bool isDisposing)
{

View File

@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Common;
using SharpCompress.Compressors;
using SharpCompress.Compressors.Deflate;
@@ -50,4 +52,15 @@ public sealed class GZipWriter : AbstractWriter
source.TransferTo(stream);
_wroteToStream = true;
}
#if !NETFRAMEWORK && !NETSTANDARD2_0
public override ValueTask DisposeAsync() => throw new NotImplementedException();
public override ValueTask WriteAsync(
string filename,
Stream source,
DateTime? modificationTime,
CancellationToken cancellationToken
) => throw new NotImplementedException();
#endif
}

View File

@@ -1,11 +1,24 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Common;
namespace SharpCompress.Writers;
public interface IWriter : IDisposable
#if !NETFRAMEWORK && !NETSTANDARD2_0
, IAsyncDisposable
#endif
{
ArchiveType WriterType { get; }
void Write(string filename, Stream source, DateTime? modificationTime);
#if !NETFRAMEWORK && !NETSTANDARD2_0
ValueTask WriteAsync(
string filename,
Stream source,
DateTime? modificationTime,
CancellationToken cancellationToken
);
#endif
}

View File

@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Common;
using SharpCompress.Common.Tar.Headers;
using SharpCompress.Compressors;
@@ -126,4 +128,15 @@ public class TarWriter : AbstractWriter
}
base.Dispose(isDisposing);
}
#if !NETFRAMEWORK && !NETSTANDARD2_0
public override ValueTask DisposeAsync() => throw new NotImplementedException();
public override ValueTask WriteAsync(
string filename,
Stream source,
DateTime? modificationTime,
CancellationToken cancellationToken
) => throw new NotImplementedException();
#endif
}

File diff suppressed because it is too large Load Diff