/// <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."); } }
public XZOutputStream(Stream s, int threads, uint preset, bool leaveOpen) { this.innerStream = s; this.leaveOpen = leaveOpen; LzmaResult ret; if (threads == 1 || !NativeMethods.SupportsMultiThreading) { ret = NativeMethods.lzma_easy_encoder(ref this.lzmaStream, preset, LzmaCheck.Crc64); } else { if (threads <= 0) { throw new ArgumentOutOfRangeException(nameof(threads)); } if (threads > Environment.ProcessorCount) { Trace.TraceWarning("{0} threads required, but only {1} processors available", threads, Environment.ProcessorCount); threads = Environment.ProcessorCount; } var mt = new LzmaMT() { preset = preset, check = LzmaCheck.Crc64, threads = (uint)threads }; ret = NativeMethods.lzma_stream_encoder_mt(ref this.lzmaStream, ref mt); } if (ret == LzmaResult.OK) { this.outbuf = new byte[BufSize]; this.lzmaStream.AvailOut = BufSize; return; } GC.SuppressFinalize(this); throw GetError(ret); }
internal static extern LzmaResult lzma_stream_encoder_mt(ref LzmaStream stream, ref LzmaMT mt);