mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-22 15:04:43 +00:00
Redo options classes
This commit is contained in:
@@ -182,7 +182,7 @@ namespace SharpCompress.Archives.Tar
|
||||
IEnumerable<TarArchiveEntry> oldEntries,
|
||||
IEnumerable<TarArchiveEntry> newEntries)
|
||||
{
|
||||
using (var writer = new TarWriter(stream, new TarWriterOptions(options)))
|
||||
using (var writer = new TarWriter(stream, options))
|
||||
{
|
||||
foreach (var entry in oldEntries.Concat(newEntries)
|
||||
.Where(x => !x.IsDirectory))
|
||||
|
||||
10
src/SharpCompress/Common/OptionsBase.cs
Normal file
10
src/SharpCompress/Common/OptionsBase.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
public class OptionsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// SharpCompress will keep the supplied streams open. Default is true.
|
||||
/// </summary>
|
||||
public bool LeaveOpenStream { get; set; } = true;
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,8 @@
|
||||
|
||||
namespace SharpCompress.Readers
|
||||
{
|
||||
public class ReaderOptions
|
||||
public class ReaderOptions : OptionsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// SharpCompress will keep the supplied streams open. Default is true.
|
||||
/// </summary>
|
||||
public virtual bool LeaveOpenStream { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Look for RarArchive (Check for self-extracting archives or cases where RarArchive isn't at the start of the file)
|
||||
/// </summary>
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace SharpCompress.Writers.Tar
|
||||
{
|
||||
public class TarWriter : AbstractWriter
|
||||
{
|
||||
public TarWriter(Stream destination, TarWriterOptions options)
|
||||
public TarWriter(Stream destination, WriterOptions options)
|
||||
: base(ArchiveType.Tar)
|
||||
{
|
||||
if (!destination.CanWrite)
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Writers.Tar
|
||||
{
|
||||
public class TarWriterOptions
|
||||
{
|
||||
public TarWriterOptions()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal TarWriterOptions(WriterOptions readerOptions)
|
||||
{
|
||||
LeaveOpenStream = readerOptions.LeaveOpenStream;
|
||||
CompressionType = readerOptions.CompressionType;
|
||||
}
|
||||
|
||||
public bool LeaveOpenStream { get; set; }
|
||||
|
||||
public CompressionType CompressionType { get; set; } = CompressionType.Unknown;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace SharpCompress.Writers
|
||||
}
|
||||
case ArchiveType.Tar:
|
||||
{
|
||||
return new TarWriter(stream, new TarWriterOptions(writerOptions));
|
||||
return new TarWriter(stream, writerOptions);
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
@@ -3,21 +3,13 @@ using SharpCompress.Compressors.Deflate;
|
||||
|
||||
namespace SharpCompress.Writers
|
||||
{
|
||||
public class WriterOptions
|
||||
public class WriterOptions : OptionsBase
|
||||
{
|
||||
public WriterOptions(CompressionType compressionType)
|
||||
{
|
||||
CompressionType = compressionType;
|
||||
}
|
||||
public CompressionType CompressionType { get; set; } = CompressionType.Unknown;
|
||||
|
||||
public bool LeaveOpenStream { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// When CompressionType.Deflate is used, this property is referenced. Defaults to CompressionLevel.Default.
|
||||
/// </summary>
|
||||
public CompressionLevel DeflateCompressionLevel { get; set; } = CompressionLevel.Default;
|
||||
public CompressionType CompressionType { get; set; }
|
||||
|
||||
public static implicit operator WriterOptions(CompressionType compressionType)
|
||||
{
|
||||
|
||||
@@ -4,22 +4,18 @@ using SharpCompress.Compressors.Deflate;
|
||||
|
||||
namespace SharpCompress.Writers.Zip
|
||||
{
|
||||
public class ZipWriterOptions
|
||||
public class ZipWriterOptions : WriterOptions
|
||||
{
|
||||
public ZipWriterOptions()
|
||||
public ZipWriterOptions(CompressionType compressionType)
|
||||
: base(compressionType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
internal ZipWriterOptions(WriterOptions options)
|
||||
: base(options.CompressionType)
|
||||
{
|
||||
LeaveOpenStream = options.LeaveOpenStream;
|
||||
CompressionType = options.CompressionType;
|
||||
}
|
||||
|
||||
public bool LeaveOpenStream { get; set; }
|
||||
|
||||
public CompressionType CompressionType { get; set; } = CompressionType.Unknown;
|
||||
/// <summary>
|
||||
/// When CompressionType.Deflate is used, this property is referenced. Defaults to CompressionLevel.Default.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user