mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-25 08:24:58 +00:00
add writer support for async
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user