Example #1
0
        /// <summary>
        /// Create multi-threaded compressing XZStream. Requires more memory than single-threaded mode.
        /// </summary>
        public unsafe XZStream(Stream baseStream, XZCompressOptions compOpts, XZThreadedCompressOptions threadOpts)
        {
            XZInit.Manager.EnsureLoaded();

            BaseStream = baseStream ?? throw new ArgumentNullException(nameof(baseStream));
            _mode      = Mode.Compress;
            _disposed  = false;

            // Check and set XZStreamOptions
            _leaveOpen  = compOpts.LeaveOpen;
            _bufferSize = CheckBufferSize(compOpts.BufferSize);
            _workBuf    = new byte[_bufferSize];

            // Prepare LzmaStream and buffers
            _lzmaStream    = new LzmaStream();
            _lzmaStreamPin = GCHandle.Alloc(_lzmaStream, GCHandleType.Pinned);

            // Check LzmaMt instance
            LzmaMt mt = compOpts.ToLzmaMt(threadOpts);

            CheckPreset(mt.Preset);

            // Initialize the encoder
            LzmaRet ret = XZInit.Lib.LzmaStreamEncoderMt(_lzmaStream, mt);

            XZException.CheckReturnValue(ret);

            // Set possible max memory usage.
            MaxMemUsage = XZInit.Lib.LzmaStreamEncoderMtMemUsage(mt);
        }
Example #2
0
        /// <summary>
        /// Calculate approximate memory usage of multithreaded .xz encoder
        /// </summary>
        /// <returns>
        /// Number of bytes of memory required for encoding with the given options.
        /// If an error occurs, for example due to unsupported preset or filter chain, UINT64_MAX is returned.
        /// </returns>
        public static ulong EncoderMultiMemUsage(XZCompressOptions compOpts, XZThreadedCompressOptions threadOpts)
        {
            Manager.EnsureLoaded();

            LzmaMt mtOpts = compOpts.ToLzmaMt(threadOpts);

            return(Lib.LzmaStreamEncoderMtMemUsage(mtOpts));
        }
Example #3
0
 internal LzmaMt ToLzmaMt(XZThreadedCompressOptions threadOpts)
 {
     return(new LzmaMt()
     {
         BlockSize = threadOpts.BlockSize,
         Threads = XZThreadedCompressOptions.CheckThreadCount(threadOpts.Threads),
         Preset = Preset,
         Check = Check,
     });
 }