| | | 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 | | |
| | | 4 | | namespace 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> |
| | 0 | 12 | | public static int DefaultWindowLog2 => ZLibNative.DefaultWindowLog; |
| | | 13 | | |
| | | 14 | | /// <summary>Gets the minimum base-2 logarithm of the window size for zlib compression.</summary> |
| | 0 | 15 | | public static int MinWindowLog2 => ZLibNative.MinWindowLog; |
| | | 16 | | |
| | | 17 | | /// <summary>Gets the maximum base-2 logarithm of the window size for zlib compression.</summary> |
| | 0 | 18 | | public static int MaxWindowLog2 => ZLibNative.MaxWindowLog; |
| | | 19 | | |
| | 0 | 20 | | private int _compressionLevel = -1; |
| | | 21 | | private ZLibCompressionStrategy _strategy; |
| | 0 | 22 | | 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 | | { |
| | 0 | 34 | | get => _compressionLevel; |
| | | 35 | | set |
| | 0 | 36 | | { |
| | 0 | 37 | | if (value != -1) |
| | 0 | 38 | | { |
| | 0 | 39 | | ArgumentOutOfRangeException.ThrowIfLessThan(value, ZLibNative.MinQuality, nameof(value)); |
| | 0 | 40 | | ArgumentOutOfRangeException.ThrowIfGreaterThan(value, ZLibNative.MaxQuality, nameof(value)); |
| | 0 | 41 | | } |
| | | 42 | | |
| | 0 | 43 | | _compressionLevel = value; |
| | 0 | 44 | | } |
| | | 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 | | { |
| | 0 | 53 | | get => _strategy; |
| | | 54 | | set |
| | 0 | 55 | | { |
| | 0 | 56 | | ArgumentOutOfRangeException.ThrowIfLessThan((int)value, (int) ZLibCompressionStrategy.Default, nameof(va |
| | 0 | 57 | | ArgumentOutOfRangeException.ThrowIfGreaterThan((int)value, (int)ZLibCompressionStrategy.Fixed, nameof(va |
| | | 58 | | |
| | 0 | 59 | | _strategy = value; |
| | 0 | 60 | | } |
| | | 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 | | { |
| | 0 | 74 | | get => _windowLog2; |
| | | 75 | | set |
| | 0 | 76 | | { |
| | 0 | 77 | | if (value != -1) |
| | 0 | 78 | | { |
| | 0 | 79 | | ArgumentOutOfRangeException.ThrowIfLessThan(value, ZLibNative.MinWindowLog, nameof(value)); |
| | 0 | 80 | | ArgumentOutOfRangeException.ThrowIfGreaterThan(value, ZLibNative.MaxWindowLog, nameof(value)); |
| | 0 | 81 | | } |
| | | 82 | | |
| | 0 | 83 | | _windowLog2 = value; |
| | 0 | 84 | | } |
| | | 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 | | } |