< Summary

Information
Class: System.IO.Compression.ZLibCompressionOptions
Assembly: System.IO.Compression
File(s): D:\runner\runtime\src\libraries\System.IO.Compression\src\System\IO\Compression\ZLibCompressionOptions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 115
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%

File(s)

D:\runner\runtime\src\libraries\System.IO.Compression\src\System\IO\Compression\ZLibCompressionOptions.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4namespace System.IO.Compression
 5{
 6    /// <summary>
 7    /// Provides compression options to be used with <see cref="ZLibStream"/>, <see cref="DeflateStream"/> and <see cref
 8    /// </summary>
 9    public sealed class ZLibCompressionOptions
 10    {
 11        /// <summary>Gets the default base-2 logarithm of the window size for zlib compression.</summary>
 012        public static int DefaultWindowLog2 => ZLibNative.DefaultWindowLog;
 13
 14        /// <summary>Gets the minimum base-2 logarithm of the window size for zlib compression.</summary>
 015        public static int MinWindowLog2 => ZLibNative.MinWindowLog;
 16
 17        /// <summary>Gets the maximum base-2 logarithm of the window size for zlib compression.</summary>
 018        public static int MaxWindowLog2 => ZLibNative.MaxWindowLog;
 19
 020        private int _compressionLevel = -1;
 21        private ZLibCompressionStrategy _strategy;
 022        private int _windowLog2 = -1;
 23
 24        /// <summary>
 25        /// Gets or sets the compression level for a compression stream.
 26        /// </summary>
 27        /// <exception cref="ArgumentOutOfRangeException">The value is less than -1 or greater than 9.</exception>
 28        /// <remarks>
 29        /// Can accept any value between -1 and 9 (inclusive), 0 gives no compression, 1 gives best speed, 9 gives best 
 30        /// The default value is -1.
 31        /// </remarks>
 32        public int CompressionLevel
 33        {
 034            get => _compressionLevel;
 35            set
 036            {
 037                if (value != -1)
 038                {
 039                    ArgumentOutOfRangeException.ThrowIfLessThan(value, ZLibNative.MinQuality, nameof(value));
 040                    ArgumentOutOfRangeException.ThrowIfGreaterThan(value, ZLibNative.MaxQuality, nameof(value));
 041                }
 42
 043                _compressionLevel = value;
 044            }
 45        }
 46
 47        /// <summary>
 48        /// Gets or sets the compression algorithm for a compression stream.
 49        /// </summary>
 50        /// <exception cref="ArgumentOutOfRangeException" >The value is not a valid <see cref="ZLibCompressionStrategy"/
 51        public ZLibCompressionStrategy CompressionStrategy
 52        {
 053            get => _strategy;
 54            set
 055            {
 056                ArgumentOutOfRangeException.ThrowIfLessThan((int)value, (int) ZLibCompressionStrategy.Default, nameof(va
 057                ArgumentOutOfRangeException.ThrowIfGreaterThan((int)value, (int)ZLibCompressionStrategy.Fixed, nameof(va
 58
 059                _strategy = value;
 060            }
 61        }
 62
 63        /// <summary>
 64        /// Gets or sets the base-2 logarithm of the window size for a compression stream.
 65        /// </summary>
 66        /// <exception cref="ArgumentOutOfRangeException">The value is less than -1 or greater than 15, or between 0 and
 67        /// <remarks>
 68        /// Can accept -1 or any value between 8 and 15 (inclusive). Larger values result in better compression at the e
 69        /// When used with <see cref="DeflateStream"/> or <see cref="GZipStream"/>, a value of 8 is treated as 9 by the 
 70        /// -1 requests the default base-2 logarithm of the window size, which is currently equivalent to 15 (32KB windo
 71        /// </remarks>
 72        public int WindowLog2
 73        {
 074            get => _windowLog2;
 75            set
 076            {
 077                if (value != -1)
 078                {
 079                    ArgumentOutOfRangeException.ThrowIfLessThan(value, ZLibNative.MinWindowLog, nameof(value));
 080                    ArgumentOutOfRangeException.ThrowIfGreaterThan(value, ZLibNative.MaxWindowLog, nameof(value));
 081                }
 82
 083                _windowLog2 = value;
 084            }
 85        }
 86    }
 87
 88    /// <summary>
 89    /// Defines the compression algorithms that can be used for <see cref="DeflateStream"/>, <see cref="GZipStream"/> or
 90    /// </summary>
 91    public enum ZLibCompressionStrategy
 92    {
 93        /// <summary>
 94        /// Used for normal data.
 95        /// </summary>
 96        Default = 0,
 97        /// <summary>
 98        /// Used for data produced by a filter (or predictor). The effect of Filtered is to force more Huffman
 99        /// coding and less string matching, intermediate between Default and HuffmanOnly.
 100        /// </summary>
 101        Filtered = 1,
 102        /// <summary>
 103        /// Used to force Huffman encoding only (no string match).
 104        /// </summary>
 105        HuffmanOnly = 2,
 106        /// <summary>
 107        /// Used to limit match distances to one (run-length encoding), give better compression for PNG image data.
 108        /// </summary>
 109        RunLengthEncoding = 3,
 110        /// <summary>
 111        /// Prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications.
 112        /// </summary>
 113        Fixed = 4
 114    }
 115}