< Summary

Line coverage
4%
Covered lines: 2
Uncovered lines: 40
Coverable lines: 42
Total lines: 245
Line coverage: 4.7%
Branch coverage
3%
Covered branches: 1
Total branches: 32
Branch coverage: 3.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

C:\projects\jeremyansel-io-locator\JeremyAnsel.IO.Locator\JeremyAnsel.IO.Locator\WritableFileLocatorFactory.cs

#LineLine coverage
 1// <copyright file="WritableFileLocatorFactory.cs" company="Jérémy Ansel">
 2// Copyright (c) 2015, 2019 Jérémy Ansel
 3// </copyright>
 4// <license>
 5// Licensed under the MIT license. See LICENSE.txt
 6// </license>
 7
 8namespace JeremyAnsel.IO.Locator
 9{
 10    using System;
 11    using System.Diagnostics.CodeAnalysis;
 12    using System.IO;
 13    using SharpCompress.Common;
 14
 15    /// <summary>
 16    /// A factory to create a writable file locator.
 17    /// <para>
 18    /// The supported formats are: file system, Zip, Tar, GZip.
 19    /// </para>
 20    /// </summary>
 21    public static class WritableFileLocatorFactory
 22    {
 23        /// <summary>
 24        /// Creates a writable file locator.
 25        /// </summary>
 26        /// <param name="root">The root path.</param>
 27        /// <returns>A writable file locator.</returns>
 28        [SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "Reviewed")]
 29        public static IWritableFileLocator Create(string root)
 30        {
 031            if (string.IsNullOrEmpty(root))
 32            {
 033                throw new ArgumentNullException(nameof(root));
 34            }
 35
 036            string ext = Path.GetExtension(root);
 37
 038            if (!string.IsNullOrEmpty(ext))
 39            {
 040                switch (ext.ToLowerInvariant())
 41                {
 42                    case ".zip":
 043                        return new ArchiveWritableFileLocator(root, ArchiveType.Zip, CompressionType.Deflate);
 44
 45                    case ".gz":
 046                        return new ArchiveWritableFileLocator(root, ArchiveType.GZip, CompressionType.GZip);
 47
 48                    default:
 049                        throw new NotSupportedException();
 50                }
 51            }
 52
 053            return new SystemWritableFileLocator(root);
 54        }
 55
 56        /// <summary>
 57        /// Creates a writable file locator for an archive.
 58        /// </summary>
 59        /// <param name="root">The root path.</param>
 60        /// <param name="archiveType">The archive type.</param>
 61        /// <param name="compressionType">The compression type.</param>
 62        /// <returns>A writable file locator.</returns>
 63        public static IWritableFileLocator CreateArchive(string root, ArchiveType archiveType, CompressionType compressi
 64        {
 065            if (string.IsNullOrEmpty(root))
 66            {
 067                throw new ArgumentNullException(nameof(root));
 68            }
 69
 070            return new ArchiveWritableFileLocator(root, archiveType, compressionType);
 71        }
 72
 73        /// <summary>
 74        /// Creates a writable file locator for an archive.
 75        /// </summary>
 76        /// <param name="root">The root path.</param>
 77        /// <param name="archiveType">The archive type.</param>
 78        /// <returns>A writable file locator.</returns>
 79        public static IWritableFileLocator CreateArchive(string root, ArchiveType archiveType)
 80        {
 081            if (string.IsNullOrEmpty(root))
 82            {
 083                throw new ArgumentNullException(nameof(root));
 84            }
 85
 086            return new ArchiveWritableFileLocator(root, archiveType, CompressionType.Deflate);
 87        }
 88
 89        /// <summary>
 90        /// Creates a writable file locator for an archive from a stream.
 91        /// </summary>
 92        /// <param name="root">A stream</param>
 93        /// <param name="archiveType">The archive type.</param>
 94        /// <param name="compressionType">The compression type.</param>
 95        /// <returns>A writable file locator.</returns>
 96        public static IWritableFileLocator CreateArchive(Stream root, ArchiveType archiveType, CompressionType compressi
 97        {
 098            if (root == null)
 99            {
 0100                throw new ArgumentNullException(nameof(root));
 101            }
 102
 0103            return new ArchiveWritableFileLocator(root, archiveType, compressionType);
 104        }
 105
 106        /// <summary>
 107        /// Creates a writable file locator for an archive from a stream.
 108        /// </summary>
 109        /// <param name="root">A stream.</param>
 110        /// <param name="archiveType">The archive type.</param>
 111        /// <returns>A writable file locator.</returns>
 112        public static IWritableFileLocator CreateArchive(Stream root, ArchiveType archiveType)
 113        {
 0114            if (root == null)
 115            {
 0116                throw new ArgumentNullException(nameof(root));
 117            }
 118
 0119            return new ArchiveWritableFileLocator(root, archiveType, CompressionType.Deflate);
 120        }
 121    }
 122}

https://raw.githubusercontent.com/JeremyAnsel/JeremyAnsel.IO.Locator/16c8f4344390c6376cd2208cc1ae63a39862df37/JeremyAnsel.IO.Locator/JeremyAnsel.IO.Locator/WritableFileLocatorFactory.cs

#LineLine coverage
 1// <copyright file="WritableFileLocatorFactory.cs" company="Jérémy Ansel">
 2// Copyright (c) 2015, 2019 Jérémy Ansel
 3// </copyright>
 4// <license>
 5// Licensed under the MIT license. See LICENSE.txt
 6// </license>
 7
 8namespace JeremyAnsel.IO.Locator
 9{
 10    using System;
 11    using System.Diagnostics.CodeAnalysis;
 12    using System.IO;
 13    using SharpCompress.Common;
 14
 15    /// <summary>
 16    /// A factory to create a writable file locator.
 17    /// <para>
 18    /// The supported formats are: file system, Zip, Tar, GZip.
 19    /// </para>
 20    /// </summary>
 21    public static class WritableFileLocatorFactory
 22    {
 23        /// <summary>
 24        /// Creates a writable file locator.
 25        /// </summary>
 26        /// <param name="root">The root path.</param>
 27        /// <returns>A writable file locator.</returns>
 28        [SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "Reviewed")]
 29        public static IWritableFileLocator Create(string root)
 30        {
 031            if (string.IsNullOrEmpty(root))
 32            {
 033                throw new ArgumentNullException(nameof(root));
 34            }
 35
 036            string ext = Path.GetExtension(root);
 37
 038            if (!string.IsNullOrEmpty(ext))
 39            {
 040                switch (ext.ToLowerInvariant())
 41                {
 42                    case ".zip":
 043                        return new ArchiveWritableFileLocator(root, ArchiveType.Zip, CompressionType.Deflate);
 44
 45                    case ".gz":
 046                        return new ArchiveWritableFileLocator(root, ArchiveType.GZip, CompressionType.GZip);
 47
 48                    default:
 049                        throw new NotSupportedException();
 50                }
 51            }
 52
 053            return new SystemWritableFileLocator(root);
 54        }
 55
 56        /// <summary>
 57        /// Creates a writable file locator for an archive.
 58        /// </summary>
 59        /// <param name="root">The root path.</param>
 60        /// <param name="archiveType">The archive type.</param>
 61        /// <param name="compressionType">The compression type.</param>
 62        /// <returns>A writable file locator.</returns>
 63        public static IWritableFileLocator CreateArchive(string root, ArchiveType archiveType, CompressionType compressi
 64        {
 465            if (string.IsNullOrEmpty(root))
 66            {
 067                throw new ArgumentNullException(nameof(root));
 68            }
 69
 470            return new ArchiveWritableFileLocator(root, archiveType, compressionType);
 71        }
 72
 73        /// <summary>
 74        /// Creates a writable file locator for an archive.
 75        /// </summary>
 76        /// <param name="root">The root path.</param>
 77        /// <param name="archiveType">The archive type.</param>
 78        /// <returns>A writable file locator.</returns>
 79        public static IWritableFileLocator CreateArchive(string root, ArchiveType archiveType)
 80        {
 081            if (string.IsNullOrEmpty(root))
 82            {
 083                throw new ArgumentNullException(nameof(root));
 84            }
 85
 086            return new ArchiveWritableFileLocator(root, archiveType, CompressionType.Deflate);
 87        }
 88
 89        /// <summary>
 90        /// Creates a writable file locator for an archive from a stream.
 91        /// </summary>
 92        /// <param name="root">A stream</param>
 93        /// <param name="archiveType">The archive type.</param>
 94        /// <param name="compressionType">The compression type.</param>
 95        /// <returns>A writable file locator.</returns>
 96        public static IWritableFileLocator CreateArchive(Stream root, ArchiveType archiveType, CompressionType compressi
 97        {
 098            if (root == null)
 99            {
 0100                throw new ArgumentNullException(nameof(root));
 101            }
 102
 0103            return new ArchiveWritableFileLocator(root, archiveType, compressionType);
 104        }
 105
 106        /// <summary>
 107        /// Creates a writable file locator for an archive from a stream.
 108        /// </summary>
 109        /// <param name="root">A stream.</param>
 110        /// <param name="archiveType">The archive type.</param>
 111        /// <returns>A writable file locator.</returns>
 112        public static IWritableFileLocator CreateArchive(Stream root, ArchiveType archiveType)
 113        {
 0114            if (root == null)
 115            {
 0116                throw new ArgumentNullException(nameof(root));
 117            }
 118
 0119            return new ArchiveWritableFileLocator(root, archiveType, CompressionType.Deflate);
 120        }
 121    }
 122}
 123