< Summary

Information
Class: System.IO.Compression.CompressionFormatHelper
Assembly: System.IO.Compression
File(s): D:\runner\runtime\src\libraries\System.IO.Compression\src\System\IO\Compression\CompressionFormat.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 50
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ResolveWindowBits(...)0%880%

File(s)

D:\runner\runtime\src\libraries\System.IO.Compression\src\System\IO\Compression\CompressionFormat.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    /// Specifies the compression format for zlib-based encoders.
 8    /// </summary>
 9    internal enum CompressionFormat
 10    {
 11        /// <summary>Raw deflate format (no header/trailer).</summary>
 12        Deflate,
 13        /// <summary>ZLib format (zlib header/trailer).</summary>
 14        ZLib,
 15        /// <summary>GZip format (gzip header/trailer).</summary>
 16        GZip
 17    }
 18
 19    internal static class CompressionFormatHelper
 20    {
 21        /// <summary>
 22        /// Resolves a windowLog value (8-15) to the windowBits parameter expected by zlib,
 23        /// based on the compression format. A windowLog of -1 is resolved to the default (15).
 24        /// </summary>
 25        /// <remarks>
 26        /// zlib-ng rejects windowBits 8 for raw deflate and gzip; classic zlib silently upgrades to 9.
 27        /// This method clamps to 9 for Deflate and GZip formats to match classic zlib behavior.
 28        /// </remarks>
 29        internal static int ResolveWindowBits(int windowLog, CompressionFormat format)
 030        {
 031            if (windowLog == -1)
 032            {
 033                windowLog = ZLibNative.DefaultWindowLog;
 034            }
 35
 036            if (format != CompressionFormat.ZLib)
 037            {
 038                windowLog = Math.Max(windowLog, 9);
 039            }
 40
 041            return format switch
 042            {
 043                CompressionFormat.Deflate => -windowLog,
 044                CompressionFormat.ZLib => windowLog,
 045                CompressionFormat.GZip => windowLog + 16,
 046                _ => throw new ArgumentOutOfRangeException(nameof(format))
 047            };
 048        }
 49    }
 50}