public XZOutputStream(Stream s, int threads) { if (threads <= 0) { throw new ArgumentOutOfRangeException("threads"); } if (threads > Environment.ProcessorCount) { Trace.TraceWarning("{0} threads required, but only {1} processors available", threads, Environment.ProcessorCount); threads = Environment.ProcessorCount; } _mInnerStream = s; var mt = new LzmaMT() { flags = 0, block_size = 0, timeout = 0, preset = Preset, filters = IntPtr.Zero, check = LzmaCheck.LzmaCheckCrc64, threads = (uint)threads }; var ret = Native.lzma_stream_encoder_mt(ref _lzmaStream, ref mt); //var ret = Native.lzma_easy_encoder(ref _lzmaStream, Preset, LzmaCheck.LzmaCheckCrc64); _inbuf = Marshal.AllocHGlobal(BufSize); _outbuf = Marshal.AllocHGlobal(BufSize); _lzmaStream.avail_in = 0; _lzmaStream.next_out = _outbuf; _lzmaStream.avail_out = BufSize; if (ret == LzmaReturn.LzmaOK) { return; } switch (ret) { case LzmaReturn.LzmaMemError: throw new Exception("Memory allocation failed"); case LzmaReturn.LzmaOptionsError: throw new Exception("Specified preset is not supported"); case LzmaReturn.LzmaUnsupportedCheck: throw new Exception("Specified integrity check is not supported"); default: throw new Exception("Unknown error, possibly a bug"); } }
public XZOutputStream(Stream s) { _mInnerStream = s; var mt = new LzmaMT() { flags = 0, block_size = 0, timeout = 0, preset = Preset, filters = IntPtr.Zero, check = LzmaCheck.LzmaCheckCrc64, threads = (uint)Environment.ProcessorCount }; if (mt.threads > MaxThreads) { mt.threads = MaxThreads; } var ret = Native.lzma_stream_encoder_mt(ref _lzmaStream, ref mt); //var ret = Native.lzma_easy_encoder(ref _lzmaStream, Preset, LzmaCheck.LzmaCheckCrc64); _inbuf = Marshal.AllocHGlobal(BufSize); _outbuf = Marshal.AllocHGlobal(BufSize); _lzmaStream.avail_in = 0; _lzmaStream.next_out = _outbuf; _lzmaStream.avail_out = BufSize; if (ret == LzmaReturn.LzmaOK) { return; } switch (ret) { case LzmaReturn.LzmaMemError: throw new Exception("Memory allocation failed"); case LzmaReturn.LzmaOptionsError: throw new Exception("Specified preset is not supported"); case LzmaReturn.LzmaUnsupportedCheck: throw new Exception("Specified integrity check is not supported"); default: throw new Exception("Unknown error, possibly a bug"); } }
public XZOutputStream(Stream s) { _mInnerStream = s; var mt = new LzmaMT() { flags = 0, block_size = 0, timeout = 0, preset = Preset, filters = IntPtr.Zero, check = LzmaCheck.LzmaCheckCrc64, threads = (uint)Environment.ProcessorCount }; if (mt.threads > MaxThreads) mt.threads = MaxThreads; var ret = Native.lzma_stream_encoder_mt(ref _lzmaStream, ref mt); //var ret = Native.lzma_easy_encoder(ref _lzmaStream, Preset, LzmaCheck.LzmaCheckCrc64); _inbuf = Marshal.AllocHGlobal(BufSize); _outbuf = Marshal.AllocHGlobal(BufSize); _lzmaStream.avail_in = 0; _lzmaStream.next_out = _outbuf; _lzmaStream.avail_out = BufSize; if (ret == LzmaReturn.LzmaOK) return; switch (ret) { case LzmaReturn.LzmaMemError: throw new Exception("Memory allocation failed"); case LzmaReturn.LzmaOptionsError: throw new Exception("Specified preset is not supported"); case LzmaReturn.LzmaUnsupportedCheck: throw new Exception("Specified integrity check is not supported"); default: throw new Exception("Unknown error, possibly a bug"); } }
public XZOutputStream(Stream s, int threads, uint preset, bool leaveOpen) { _mInnerStream = s; this.leaveOpen = leaveOpen; LzmaReturn ret; if (threads == 1) { ret = Native.lzma_easy_encoder(ref _lzmaStream, preset, LzmaCheck.LzmaCheckCrc64); } 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.LzmaCheckCrc64, threads = (uint)threads }; ret = Native.lzma_stream_encoder_mt(ref _lzmaStream, ref mt); } if (ret == LzmaReturn.LzmaOK) { _outbuf = new byte[BufSize]; _lzmaStream.avail_out = (UIntPtr)BufSize; return; } GC.SuppressFinalize(this); throw GetError(ret); }
internal static extern LzmaReturn lzma_stream_encoder_mt(ref LzmaStream stream, ref LzmaMT mt);
internal static LzmaReturn lzma_stream_encoder_mt(ref LzmaStream stream, ref LzmaMT mt) => IntPtr.Size > 4 ? X64.lzma_stream_encoder_mt(ref stream, ref mt) : X86.lzma_stream_encoder_mt(ref stream, ref mt);