Files
sharpcompress/src/SharpCompress/Writers/WriterFactory.cs
2016-09-29 10:55:04 +01:00

39 lines
1.3 KiB
C#

using System;
using System.IO;
using SharpCompress.Common;
using SharpCompress.Writers.GZip;
using SharpCompress.Writers.Tar;
using SharpCompress.Writers.Zip;
namespace SharpCompress.Writers
{
public static class WriterFactory
{
public static IWriter Open(Stream stream, ArchiveType archiveType, WriterOptions writerOptions)
{
switch (archiveType)
{
case ArchiveType.GZip:
{
if (writerOptions.CompressionType != CompressionType.GZip)
{
throw new InvalidFormatException("GZip archives only support GZip compression type.");
}
return new GZipWriter(stream, writerOptions.LeaveStreamOpen);
}
case ArchiveType.Zip:
{
return new ZipWriter(stream, new ZipWriterOptions(writerOptions));
}
case ArchiveType.Tar:
{
return new TarWriter(stream, writerOptions);
}
default:
{
throw new NotSupportedException("Archive Type does not have a Writer: " + archiveType);
}
}
}
}
}