WriterFactory.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.IO;
  3. using SharpCompress.Common;
  4. using SharpCompress.Writers.GZip;
  5. using SharpCompress.Writers.Tar;
  6. using SharpCompress.Writers.Zip;
  7. namespace SharpCompress.Writers
  8. {
  9. public static class WriterFactory
  10. {
  11. public static IWriter Open(Stream stream, ArchiveType archiveType, WriterOptions writerOptions)
  12. {
  13. switch (archiveType)
  14. {
  15. case ArchiveType.GZip:
  16. {
  17. if (writerOptions.CompressionType != CompressionType.GZip)
  18. {
  19. throw new InvalidFormatException("GZip archives only support GZip compression type.");
  20. }
  21. return new GZipWriter(stream, new GZipWriterOptions(writerOptions));
  22. }
  23. case ArchiveType.Zip:
  24. {
  25. return new ZipWriter(stream, new ZipWriterOptions(writerOptions));
  26. }
  27. case ArchiveType.Tar:
  28. {
  29. return new TarWriter(stream, new TarWriterOptions(writerOptions));
  30. }
  31. default:
  32. {
  33. throw new NotSupportedException("Archive Type does not have a Writer: " + archiveType);
  34. }
  35. }
  36. }
  37. }
  38. }