/// <summary> /// Allocate a decompressor for the specified compression type. /// This function is part of wimlib's compression API; it is not necessary to call this to process a WIM file. /// </summary> /// <param name="ctype"> /// Compression type for which to create the decompressor, as one of the <see cref="CompressionType"/> constants. /// </param> /// <param name="maxBlockSize"> /// The maximum compression block size to support. /// <para>This specifies the maximum allowed value for the uncompressedSize parameter of <see cref="Decompress()"/> when called using this decompressor.</para> /// <para>In general, this parameter must be the same as the maxBlockSize that was passed to <see cref="Compressor.CreateCompressor()"/> when the data was compressed. /// However, some compression types have looser requirements regarding this.</para> /// </param> /// <returns> /// On success, a new instance of the allocated <see cref="Decompressor"/>, which can be used for any number of calls to <see cref="Decompressor.Decompress()"/>. /// This instance must be disposed manually. /// </returns> /// <exception cref="WimLibException">wimlib did not return <see cref="ErrorCode.Success"/>.</exception> public static Decompressor Create(CompressionType ctype, int maxBlockSize) { Manager.EnsureLoaded(); if (maxBlockSize < 0) { throw new ArgumentOutOfRangeException(nameof(maxBlockSize)); } ErrorCode ret = Lib.CreateDecompressor(ctype, new UIntPtr((uint)maxBlockSize), out IntPtr decompPtr); WimLibException.CheckErrorCode(ret); return(new Decompressor(decompPtr)); }
/// <summary> /// Allocate a compressor for the specified compression type using the specified parameters. /// This function is part of wimlib's compression API; it is not necessary to call this to process a WIM file. /// </summary> /// <param name="ctype"> /// Compression type for which to create the compressor, as one of the <see cref="CompressionType"/> constants. /// </param> /// <param name="maxBlockSize"> /// The maximum compression block size to support. /// <para>This specifies the maximum allowed value for the uncompressedSize parameter of <see cref="Compressor.Compress()"/> when called using this compressor.</para> /// <para>Usually, the amount of memory used by the compressor will scale in proportion to the <paramref name="maxBlockSize"/> parameter. /// <see cref="Wim.GetCompressorNeededMemory"/> can be used to query the specific amount of memory that will be required.</para> /// <para>This parameter must be at least 1 and must be less than or equal to a compression-type-specific limit.</para> /// </param> /// <param name="compressionLevel"> /// The compression level to use. /// <para>If 0, the default compression level (50, or another value as set through /// <see cref="Wim.SetDefaultCompressionLevel(CompressionType, uint, CompressorFlags)"/>) is used. /// Otherwise, a higher value indicates higher compression.<br/> /// The values are scaled so that 10 is low compression, 50 is medium compression, and 100 is high compression. /// This is not a percentage; values above 100 are also valid.</para> /// </param> /// <param name="compressorFlags"> /// Flag <see cref="CompressorFlags.Destructive"/> creates the compressor in a mode where it is allowed to modify the input buffer. /// <para>Specifically, in this mode, if compression succeeds, the input buffer may have been modified, /// whereas if compression does not succeed the input buffer still may have been written to but will have been restored exactly to its original state.</para> /// <para>This mode is designed to save some memory when using large buffer sizes.</para> /// </param> /// <returns> /// On success, a new instance of the allocated <see cref="Compressor"/>, which can be used for any number of calls to <see cref="Compressor.Compress()"/>. /// This instance must be disposed manually. /// </returns> /// <exception cref="WimLibException">wimlib did not return <see cref="ErrorCode.Success"/>.</exception> public static Compressor Create(CompressionType ctype, int maxBlockSize, uint compressionLevel, CompressorFlags compressorFlags) { Manager.EnsureLoaded(); if (maxBlockSize < 0) { throw new ArgumentOutOfRangeException(nameof(maxBlockSize)); } compressionLevel |= (uint)compressorFlags; ErrorCode ret = Lib.CreateCompressor(ctype, new UIntPtr((uint)maxBlockSize), compressionLevel, out IntPtr compPtr); WimLibException.CheckErrorCode(ret); return(new Compressor(compPtr)); }