/// <summary> /// <para> /// Initialize multithreaded .xz Stream encoder /// </para> /// <para> /// This provides the functionality of lzma_easy_encoder() and /// lzma_stream_encoder() as a single function for multithreaded use. /// </para> /// <para> /// The supported actions for lzma_code() are LZMA_RUN, LZMA_FULL_FLUSH, /// LZMA_FULL_BARRIER, and LZMA_FINISH. Support for LZMA_SYNC_FLUSH might be /// added in the future. /// </para> /// </summary> /// <param name="stream"> /// Pointer to properly prepared lzma_stream /// </param> /// <param name="mt"> /// Pointer to multithreaded compression options /// </param> /// <returns> /// A <see cref="LzmaResult"/> value which indicates success or failure. /// </returns> public static LzmaResult lzma_stream_encoder_mt(ref LzmaStream stream, ref LzmaMT mt) { if (SupportsMultiThreading) { return(lzma_stream_encoder_mt_ptr(ref stream, ref mt)); } else { throw new PlatformNotSupportedException("lzma_stream_encoder_mt is not supported on this platform. Check SupportsMultiThreading to see whether you can use this functionality."); } }
/// <summary> /// Free memory allocated for the coder data structures /// </summary> /// <param name="stream"> /// Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. /// </param> /// <remarks> /// After <see cref="lzma_end(ref LzmaStream)"/>, <see cref="LzmaStream.InternalState"/> is guaranteed to be <see cref="IntPtr.Zero"/>. /// No other members of the <see cref="LzmaStream"/> structure are touched. /// zlib indicates an error if application end()s unfinished stream structure. /// liblzma doesn't do this, and assumes that /// application knows what it is doing. /// </remarks> /// <seealso href="https://github.com/nobled/xz/blob/master/src/liblzma/api/lzma/base.h"/> public static void lzma_end(ref LzmaStream stream) => lzma_end_ptr(ref stream);
/// <summary> /// <para> /// Initialize .xz Stream encoder using a preset number. /// </para> /// <para> /// This function is intended for those who just want to use the basic features if liblzma(that is, most developers out there). /// </para> /// <para> /// If initialization fails(return value is not LZMA_OK), all the memory allocated for *strm by liblzma is always freed.Thus, there is no need to call lzma_end() after failed initialization. /// </para> /// <para>If initialization succeeds, use lzma_code() to do the actual encoding.Valid values for `action' (the second argument of lzma_code()) are LZMA_RUN, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, and LZMA_FINISH. In future, there may be compression levels or flags that don't support LZMA_SYNC_FLUSH. /// </para> /// </summary> /// <param name="stream"> /// Pointer to lzma_stream that is at least initialized with LZMA_STREAM_INIT. /// </param> /// <param name="preset"> /// Compression preset to use. A preset consist of level number and zero or more flags. Usually flags aren't used, so preset is simply a number [0, 9] which match the options -0 ... -9 of the xz command line tool. Additional flags can be be set using bitwise-or with the preset level number, e.g. 6 | LZMA_PRESET_EXTREME. /// </param> /// <param name="check"> /// Integrity check type to use. See check.h for available checks. The xz command line tool defaults to LZMA_CHECK_CRC64, which is a good choice if you are unsure. LZMA_CHECK_CRC32 is good too as long as the uncompressed file is not many gigabytes. /// </param> /// <returns> /// <para> /// - LZMA_OK: Initialization succeeded. Use lzma_code() to encode your data. /// </para> /// <para>- LZMA_MEM_ERROR: Memory allocation failed. /// </para> /// <para> /// - LZMA_OPTIONS_ERROR: The given compression preset is not supported by this build of liblzma. /// </para> /// <para> /// - LZMA_UNSUPPORTED_CHECK: The given check type is not supported by this liblzma build. /// </para> /// <para> /// - LZMA_PROG_ERROR: One or more of the parameters have values that will never be valid. For example, strm == NULL. /// </para> /// </returns> public static LzmaResult lzma_easy_encoder(ref LzmaStream stream, uint preset, LzmaCheck check) => lzma_easy_encoder_ptr(ref stream, preset, check);
/// <summary> /// Initialize .xz Stream decoder /// </summary> /// <param name="stream"> /// Pointer to properly prepared <see cref="LzmaStream"/> /// </param> /// <param name="memLimit"> /// Memory usage limit as bytes. Use UINT64_MAX /// to effectively disable the limiter. /// </param> /// <param name="flags"> /// Bitwise-or of zero or more of the decoder flags: /// <see cref="LzmaDecodeFlags.TellNoCheck"/>, <see cref="LzmaDecodeFlags.TellUnsupportedCheck"/>, /// <see cref="LzmaDecodeFlags.TellAnyCheck"/>, <see cref="LzmaDecodeFlags.Concatenated"/>. /// </param> /// <returns> /// <see cref="LzmaResult.OK"/>: Initialization was successful, /// <see cref="LzmaResult.MemError"/>: Cannot allocate memory, /// <see cref="LzmaResult.OptionsError"/>: Unsupported flags, /// <see cref="LzmaResult.ProgError"/>. /// </returns> /// <seealso href="https://github.com/nobled/xz/blob/master/src/liblzma/api/lzma/container.h"/> public static LzmaResult lzma_stream_decoder(ref LzmaStream stream, ulong memLimit, LzmaDecodeFlags flags) => lzma_stream_decoder_ptr(ref stream, memLimit, flags);
/// <summary> /// Encode or decode data /// </summary> /// <param name="stream"> /// The <see cref="LzmaStream"/> for which to read the data. /// </param> /// <param name="action"> /// The action to perform. /// </param> /// <returns> /// A <see cref="LzmaResult"/> value. /// </returns> /// <remarks> /// <para> /// Once the <see cref="LzmaStream"/> has been successfully initialized (e.g. with /// lzma_stream_encoder()), the actual encoding or decoding is done /// using this function.The application has to update <see cref="LzmaStream.NextIn"/>, /// <see cref="LzmaStream.AvailIn"/>, <see cref="LzmaStream.NextOut"/>, and <see cref="LzmaStream.AvailOut"/> to pass input /// to and get output from liblzma. /// </para> /// <para> /// See the description of the coder-specific initialization function to find /// out what <paramref name="action"/> values are supported by the coder. /// </para> /// </remarks> public static LzmaResult lzma_code(ref LzmaStream stream, LzmaAction action) => lzma_code_ptr(ref stream, action);
internal static extern LzmaResult lzma_stream_decoder(ref LzmaStream stream, ulong memLimit, LzmaDecodeFlags flags);
internal static extern LzmaResult lzma_stream_encoder_mt(ref LzmaStream stream, ref LzmaMT mt);
internal static extern LzmaResult lzma_easy_encoder(ref LzmaStream stream, uint preset, LzmaCheck check);
internal static extern void lzma_end(ref LzmaStream stream);
internal static extern LzmaResult lzma_code(ref LzmaStream stream, LzmaAction action);