Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create single-threaded compressing XZStream.
        /// </summary>
        public unsafe XZStream(Stream baseStream, XZCompressOptions compOpts)
        {
            XZInit.Manager.EnsureLoaded();

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

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

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

            // Check preset
            uint preset = compOpts.Preset;

            CheckPreset(preset);

            // Initialize the encoder
            LzmaRet ret = XZInit.Lib.LzmaEasyEncoder(_lzmaStream, preset, compOpts.Check);

            XZException.CheckReturnValue(ret);

            // Set possible max memory usage.
            MaxMemUsage = XZInit.Lib.LzmaEasyEncoderMemUsage(preset);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculate approximate decoder memory usage of a preset
        /// </summary>
        /// <returns>
        /// Number of bytes of memory required to decompress a file that was compressed using the given preset.
        /// If an error occurs, for example due to unsupported preset, UINT64_MAX is returned.
        /// </returns>
        public static ulong DecoderMemUsage(LzmaCompLevel level, bool extremeFlag)
        {
            Manager.EnsureLoaded();

            uint preset = XZCompressOptions.ToPreset(level, extremeFlag);

            return(Lib.LzmaEasyDecoderMemUsage(preset));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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(LzmaCompLevel level, bool extremeFlag, int threads)
        {
            Manager.EnsureLoaded();

            uint   preset = XZCompressOptions.ToPreset(level, extremeFlag);
            LzmaMt mtOpts = LzmaMt.Create(preset, threads);

            return(Lib.LzmaStreamEncoderMtMemUsage(mtOpts));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Calculate approximate decoder memory usage of a preset
        /// </summary>
        /// <returns>
        /// Number of bytes of memory required to decompress a file that was compressed using the given preset.
        /// If an error occurs, for example due to unsupported preset, UINT64_MAX is returned.
        /// </returns>
        public static ulong DecoderMemUsage(XZCompressOptions compOpts)
        {
            Manager.EnsureLoaded();

            return(Lib.LzmaEasyDecoderMemUsage(compOpts.Preset));
        }