mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-24 16:05:27 +00:00
writer interfaces
This commit is contained in:
@@ -4,39 +4,42 @@ using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Writers.GZip;
|
||||
|
||||
public partial class GZipWriter : IWriterOpenable<GZipWriterOptions>
|
||||
public partial class GZipWriter : IWriterOpenable<IGZipWriter, IGZipAsyncWriter, GZipWriterOptions>
|
||||
{
|
||||
public static IWriter OpenWriter(string filePath, GZipWriterOptions writerOptions)
|
||||
public static IGZipWriter OpenWriter(string filePath, GZipWriterOptions writerOptions)
|
||||
{
|
||||
filePath.NotNullOrEmpty(nameof(filePath));
|
||||
return OpenWriter(new FileInfo(filePath), writerOptions);
|
||||
}
|
||||
|
||||
public static IWriter OpenWriter(FileInfo fileInfo, GZipWriterOptions writerOptions)
|
||||
public static IGZipWriter OpenWriter(FileInfo fileInfo, GZipWriterOptions writerOptions)
|
||||
{
|
||||
fileInfo.NotNull(nameof(fileInfo));
|
||||
return new GZipWriter(fileInfo.OpenWrite(), writerOptions);
|
||||
}
|
||||
|
||||
public static IWriter OpenWriter(Stream stream, GZipWriterOptions writerOptions)
|
||||
public static IGZipWriter OpenWriter(Stream stream, GZipWriterOptions writerOptions)
|
||||
{
|
||||
stream.NotNull(nameof(stream));
|
||||
return new GZipWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(string stream, GZipWriterOptions writerOptions)
|
||||
public static IGZipAsyncWriter OpenAsyncWriter(string filePath, GZipWriterOptions writerOptions)
|
||||
{
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
return (IGZipAsyncWriter)OpenWriter(filePath, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(Stream stream, GZipWriterOptions writerOptions)
|
||||
public static IGZipAsyncWriter OpenAsyncWriter(Stream stream, GZipWriterOptions writerOptions)
|
||||
{
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
return (IGZipAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(FileInfo fileInfo, GZipWriterOptions writerOptions)
|
||||
public static IGZipAsyncWriter OpenAsyncWriter(
|
||||
FileInfo fileInfo,
|
||||
GZipWriterOptions writerOptions
|
||||
)
|
||||
{
|
||||
return (IAsyncWriter)OpenWriter(fileInfo, writerOptions);
|
||||
return (IGZipAsyncWriter)OpenWriter(fileInfo, writerOptions);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7,7 +7,7 @@ using SharpCompress.IO;
|
||||
|
||||
namespace SharpCompress.Writers.GZip;
|
||||
|
||||
public sealed partial class GZipWriter : AbstractWriter
|
||||
public sealed partial class GZipWriter : AbstractWriter, IGZipWriter, IGZipAsyncWriter
|
||||
{
|
||||
private bool _wroteToStream;
|
||||
|
||||
|
||||
13
src/SharpCompress/Writers/GZip/IGZipWriter.cs
Normal file
13
src/SharpCompress/Writers/GZip/IGZipWriter.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using SharpCompress.Writers;
|
||||
|
||||
namespace SharpCompress.Writers.GZip;
|
||||
|
||||
/// <summary>
|
||||
/// Writer for GZip archives.
|
||||
/// </summary>
|
||||
public interface IGZipWriter : IWriter { }
|
||||
|
||||
/// <summary>
|
||||
/// Async writer for GZip archives.
|
||||
/// </summary>
|
||||
public interface IGZipAsyncWriter : IAsyncWriter { }
|
||||
@@ -5,13 +5,15 @@ using SharpCompress.Common.Options;
|
||||
|
||||
namespace SharpCompress.Writers;
|
||||
|
||||
public interface IWriterOpenable<TWriterOptions>
|
||||
public interface IWriterOpenable<TWriter, TAsyncWriter, TWriterOptions>
|
||||
where TWriter : IWriter
|
||||
where TAsyncWriter : IAsyncWriter
|
||||
where TWriterOptions : IWriterOptions
|
||||
{
|
||||
public static abstract IWriter OpenWriter(string filePath, TWriterOptions writerOptions);
|
||||
public static abstract TWriter OpenWriter(string filePath, TWriterOptions writerOptions);
|
||||
|
||||
public static abstract IWriter OpenWriter(FileInfo fileInfo, TWriterOptions writerOptions);
|
||||
public static abstract IWriter OpenWriter(Stream stream, TWriterOptions writerOptions);
|
||||
public static abstract TWriter OpenWriter(FileInfo fileInfo, TWriterOptions writerOptions);
|
||||
public static abstract TWriter OpenWriter(Stream stream, TWriterOptions writerOptions);
|
||||
|
||||
/// <summary>
|
||||
/// Opens a Writer asynchronously.
|
||||
@@ -20,17 +22,17 @@ public interface IWriterOpenable<TWriterOptions>
|
||||
/// <param name="archiveType">The archive type.</param>
|
||||
/// <param name="writerOptions">Writer options.</param>
|
||||
/// <returns>A task that returns an IWriter.</returns>
|
||||
public static abstract IAsyncWriter OpenAsyncWriter(
|
||||
public static abstract TAsyncWriter OpenAsyncWriter(
|
||||
Stream stream,
|
||||
TWriterOptions writerOptions
|
||||
);
|
||||
|
||||
public static abstract IAsyncWriter OpenAsyncWriter(
|
||||
public static abstract TAsyncWriter OpenAsyncWriter(
|
||||
string filePath,
|
||||
TWriterOptions writerOptions
|
||||
);
|
||||
|
||||
public static abstract IAsyncWriter OpenAsyncWriter(
|
||||
public static abstract TAsyncWriter OpenAsyncWriter(
|
||||
FileInfo fileInfo,
|
||||
TWriterOptions writerOptions
|
||||
);
|
||||
|
||||
13
src/SharpCompress/Writers/Tar/ITarWriter.cs
Normal file
13
src/SharpCompress/Writers/Tar/ITarWriter.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using SharpCompress.Writers;
|
||||
|
||||
namespace SharpCompress.Writers.Tar;
|
||||
|
||||
/// <summary>
|
||||
/// Writer for TAR archives.
|
||||
/// </summary>
|
||||
public interface ITarWriter : IWriter { }
|
||||
|
||||
/// <summary>
|
||||
/// Async writer for TAR archives.
|
||||
/// </summary>
|
||||
public interface ITarAsyncWriter : IAsyncWriter { }
|
||||
@@ -4,39 +4,39 @@ using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Writers.Tar;
|
||||
|
||||
public partial class TarWriter : IWriterOpenable<TarWriterOptions>
|
||||
public partial class TarWriter : IWriterOpenable<ITarWriter, ITarAsyncWriter, TarWriterOptions>
|
||||
{
|
||||
public static IWriter OpenWriter(string filePath, TarWriterOptions writerOptions)
|
||||
public static ITarWriter OpenWriter(string filePath, TarWriterOptions writerOptions)
|
||||
{
|
||||
filePath.NotNullOrEmpty(nameof(filePath));
|
||||
return OpenWriter(new FileInfo(filePath), writerOptions);
|
||||
}
|
||||
|
||||
public static IWriter OpenWriter(FileInfo fileInfo, TarWriterOptions writerOptions)
|
||||
public static ITarWriter OpenWriter(FileInfo fileInfo, TarWriterOptions writerOptions)
|
||||
{
|
||||
fileInfo.NotNull(nameof(fileInfo));
|
||||
return new TarWriter(fileInfo.OpenWrite(), writerOptions);
|
||||
}
|
||||
|
||||
public static IWriter OpenWriter(Stream stream, TarWriterOptions writerOptions)
|
||||
public static ITarWriter OpenWriter(Stream stream, TarWriterOptions writerOptions)
|
||||
{
|
||||
stream.NotNull(nameof(stream));
|
||||
return new TarWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(string stream, TarWriterOptions writerOptions)
|
||||
public static ITarAsyncWriter OpenAsyncWriter(string filePath, TarWriterOptions writerOptions)
|
||||
{
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
return (ITarAsyncWriter)OpenWriter(filePath, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(Stream stream, TarWriterOptions writerOptions)
|
||||
public static ITarAsyncWriter OpenAsyncWriter(Stream stream, TarWriterOptions writerOptions)
|
||||
{
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
return (ITarAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(FileInfo fileInfo, TarWriterOptions writerOptions)
|
||||
public static ITarAsyncWriter OpenAsyncWriter(FileInfo fileInfo, TarWriterOptions writerOptions)
|
||||
{
|
||||
return (IAsyncWriter)OpenWriter(fileInfo, writerOptions);
|
||||
return (ITarAsyncWriter)OpenWriter(fileInfo, writerOptions);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,7 @@ using SharpCompress.Providers;
|
||||
|
||||
namespace SharpCompress.Writers.Tar;
|
||||
|
||||
public partial class TarWriter : AbstractWriter
|
||||
public partial class TarWriter : AbstractWriter, ITarWriter, ITarAsyncWriter
|
||||
{
|
||||
private readonly bool finalizeArchiveOnClose;
|
||||
private TarHeaderWriteFormat headerFormat;
|
||||
|
||||
13
src/SharpCompress/Writers/Zip/IZipWriter.cs
Normal file
13
src/SharpCompress/Writers/Zip/IZipWriter.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using SharpCompress.Writers;
|
||||
|
||||
namespace SharpCompress.Writers.Zip;
|
||||
|
||||
/// <summary>
|
||||
/// Writer for ZIP archives.
|
||||
/// </summary>
|
||||
public interface IZipWriter : IWriter { }
|
||||
|
||||
/// <summary>
|
||||
/// Async writer for ZIP archives.
|
||||
/// </summary>
|
||||
public interface IZipAsyncWriter : IAsyncWriter { }
|
||||
@@ -4,39 +4,39 @@ using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Writers.Zip;
|
||||
|
||||
public partial class ZipWriter : IWriterOpenable<ZipWriterOptions>
|
||||
public partial class ZipWriter : IWriterOpenable<IZipWriter, IZipAsyncWriter, ZipWriterOptions>
|
||||
{
|
||||
public static IWriter OpenWriter(string filePath, ZipWriterOptions writerOptions)
|
||||
public static IZipWriter OpenWriter(string filePath, ZipWriterOptions writerOptions)
|
||||
{
|
||||
filePath.NotNullOrEmpty(nameof(filePath));
|
||||
return OpenWriter(new FileInfo(filePath), writerOptions);
|
||||
}
|
||||
|
||||
public static IWriter OpenWriter(FileInfo fileInfo, ZipWriterOptions writerOptions)
|
||||
public static IZipWriter OpenWriter(FileInfo fileInfo, ZipWriterOptions writerOptions)
|
||||
{
|
||||
fileInfo.NotNull(nameof(fileInfo));
|
||||
return new ZipWriter(fileInfo.OpenWrite(), writerOptions);
|
||||
}
|
||||
|
||||
public static IWriter OpenWriter(Stream stream, ZipWriterOptions writerOptions)
|
||||
public static IZipWriter OpenWriter(Stream stream, ZipWriterOptions writerOptions)
|
||||
{
|
||||
stream.NotNull(nameof(stream));
|
||||
return new ZipWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(string stream, ZipWriterOptions writerOptions)
|
||||
public static IZipAsyncWriter OpenAsyncWriter(string filePath, ZipWriterOptions writerOptions)
|
||||
{
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
return (IZipAsyncWriter)OpenWriter(filePath, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(Stream stream, ZipWriterOptions writerOptions)
|
||||
public static IZipAsyncWriter OpenAsyncWriter(Stream stream, ZipWriterOptions writerOptions)
|
||||
{
|
||||
return (IAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
return (IZipAsyncWriter)OpenWriter(stream, writerOptions);
|
||||
}
|
||||
|
||||
public static IAsyncWriter OpenAsyncWriter(FileInfo fileInfo, ZipWriterOptions writerOptions)
|
||||
public static IZipAsyncWriter OpenAsyncWriter(FileInfo fileInfo, ZipWriterOptions writerOptions)
|
||||
{
|
||||
return (IAsyncWriter)OpenWriter(fileInfo, writerOptions);
|
||||
return (IZipAsyncWriter)OpenWriter(fileInfo, writerOptions);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -20,7 +20,7 @@ using Constants = SharpCompress.Common.Constants;
|
||||
|
||||
namespace SharpCompress.Writers.Zip;
|
||||
|
||||
public partial class ZipWriter : AbstractWriter
|
||||
public partial class ZipWriter : AbstractWriter, IZipWriter, IZipAsyncWriter
|
||||
{
|
||||
private readonly CompressionType compressionType;
|
||||
private readonly int compressionLevel;
|
||||
|
||||
Reference in New Issue
Block a user