< Summary

Line coverage
4%
Covered lines: 2
Uncovered lines: 44
Coverable lines: 46
Total lines: 235
Line coverage: 4.3%
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                return ext.ToLowerInvariant() switch
 041                {
 042                    ".zip" => new ArchiveWritableFileLocator(root!, ArchiveType.Zip, CompressionType.Deflate),
 043                    ".gz" => new ArchiveWritableFileLocator(root!, ArchiveType.GZip, CompressionType.GZip),
 044                    _ => throw new NotSupportedException(),
 045                };
 46            }
 47
 048            return new SystemWritableFileLocator(root!);
 49        }
 50
 51        /// <summary>
 52        /// Creates a writable file locator for an archive.
 53        /// </summary>
 54        /// <param name="root">The root path.</param>
 55        /// <param name="archiveType">The archive type.</param>
 56        /// <param name="compressionType">The compression type.</param>
 57        /// <returns>A writable file locator.</returns>
 58        public static IWritableFileLocator CreateArchive(string? root, ArchiveType archiveType, CompressionType compress
 59        {
 060            if (string.IsNullOrEmpty(root))
 61            {
 062                throw new ArgumentNullException(nameof(root));
 63            }
 64
 065            return new ArchiveWritableFileLocator(root!, archiveType, compressionType);
 66        }
 67
 68        /// <summary>
 69        /// Creates a writable file locator for an archive.
 70        /// </summary>
 71        /// <param name="root">The root path.</param>
 72        /// <param name="archiveType">The archive type.</param>
 73        /// <returns>A writable file locator.</returns>
 74        public static IWritableFileLocator CreateArchive(string? root, ArchiveType archiveType)
 75        {
 076            if (string.IsNullOrEmpty(root))
 77            {
 078                throw new ArgumentNullException(nameof(root));
 79            }
 80
 081            return new ArchiveWritableFileLocator(root!, archiveType, CompressionType.Deflate);
 82        }
 83
 84        /// <summary>
 85        /// Creates a writable file locator for an archive from a stream.
 86        /// </summary>
 87        /// <param name="root">A stream</param>
 88        /// <param name="archiveType">The archive type.</param>
 89        /// <param name="compressionType">The compression type.</param>
 90        /// <returns>A writable file locator.</returns>
 91        public static IWritableFileLocator CreateArchive(Stream? root, ArchiveType archiveType, CompressionType compress
 92        {
 093            if (root == null)
 94            {
 095                throw new ArgumentNullException(nameof(root));
 96            }
 97
 098            return new ArchiveWritableFileLocator(root, archiveType, compressionType);
 99        }
 100
 101        /// <summary>
 102        /// Creates a writable file locator for an archive from a stream.
 103        /// </summary>
 104        /// <param name="root">A stream.</param>
 105        /// <param name="archiveType">The archive type.</param>
 106        /// <returns>A writable file locator.</returns>
 107        public static IWritableFileLocator CreateArchive(Stream? root, ArchiveType archiveType)
 108        {
 0109            if (root == null)
 110            {
 0111                throw new ArgumentNullException(nameof(root));
 112            }
 113
 0114            return new ArchiveWritableFileLocator(root, archiveType, CompressionType.Deflate);
 115        }
 116    }
 117}

https://raw.githubusercontent.com/JeremyAnsel/JeremyAnsel.IO.Locator/90359a183919dae2d6e9fc4cabae797b0df998d4/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                return ext.ToLowerInvariant() switch
 041                {
 042                    ".zip" => new ArchiveWritableFileLocator(root!, ArchiveType.Zip, CompressionType.Deflate),
 043                    ".gz" => new ArchiveWritableFileLocator(root!, ArchiveType.GZip, CompressionType.GZip),
 044                    _ => throw new NotSupportedException(),
 045                };
 46            }
 47
 048            return new SystemWritableFileLocator(root!);
 49        }
 50
 51        /// <summary>
 52        /// Creates a writable file locator for an archive.
 53        /// </summary>
 54        /// <param name="root">The root path.</param>
 55        /// <param name="archiveType">The archive type.</param>
 56        /// <param name="compressionType">The compression type.</param>
 57        /// <returns>A writable file locator.</returns>
 58        public static IWritableFileLocator CreateArchive(string? root, ArchiveType archiveType, CompressionType compress
 59        {
 660            if (string.IsNullOrEmpty(root))
 61            {
 062                throw new ArgumentNullException(nameof(root));
 63            }
 64
 665            return new ArchiveWritableFileLocator(root!, archiveType, compressionType);
 66        }
 67
 68        /// <summary>
 69        /// Creates a writable file locator for an archive.
 70        /// </summary>
 71        /// <param name="root">The root path.</param>
 72        /// <param name="archiveType">The archive type.</param>
 73        /// <returns>A writable file locator.</returns>
 74        public static IWritableFileLocator CreateArchive(string? root, ArchiveType archiveType)
 75        {
 076            if (string.IsNullOrEmpty(root))
 77            {
 078                throw new ArgumentNullException(nameof(root));
 79            }
 80
 081            return new ArchiveWritableFileLocator(root!, archiveType, CompressionType.Deflate);
 82        }
 83
 84        /// <summary>
 85        /// Creates a writable file locator for an archive from a stream.
 86        /// </summary>
 87        /// <param name="root">A stream</param>
 88        /// <param name="archiveType">The archive type.</param>
 89        /// <param name="compressionType">The compression type.</param>
 90        /// <returns>A writable file locator.</returns>
 91        public static IWritableFileLocator CreateArchive(Stream? root, ArchiveType archiveType, CompressionType compress
 92        {
 093            if (root == null)
 94            {
 095                throw new ArgumentNullException(nameof(root));
 96            }
 97
 098            return new ArchiveWritableFileLocator(root, archiveType, compressionType);
 99        }
 100
 101        /// <summary>
 102        /// Creates a writable file locator for an archive from a stream.
 103        /// </summary>
 104        /// <param name="root">A stream.</param>
 105        /// <param name="archiveType">The archive type.</param>
 106        /// <returns>A writable file locator.</returns>
 107        public static IWritableFileLocator CreateArchive(Stream? root, ArchiveType archiveType)
 108        {
 0109            if (root == null)
 110            {
 0111                throw new ArgumentNullException(nameof(root));
 112            }
 113
 0114            return new ArchiveWritableFileLocator(root, archiveType, CompressionType.Deflate);
 115        }
 116    }
 117}
 118