Example #1
0
        public Decompressor(DecompressionOptions options)
        {
            Options = options;
            dctx    = ExternMethods.ZSTD_createDCtx().EnsureZstdSuccess();

            options.ApplyDecompressionParams(dctx);
        }
Example #2
0
        public DecompressionStream(Stream stream, DecompressionOptions options, int bufferSize = 0)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("Stream is not readable", nameof(stream));
            }
            if (bufferSize < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferSize));
            }

            innerStream = stream;

            dStream = ZSTD_createDStream().EnsureZstdSuccess();
            ZSTD_DCtx_reset(dStream, ZSTD_ResetDirective.ZSTD_reset_session_only).EnsureZstdSuccess();

            if (options != null)
            {
                options.ApplyDecompressionParams(dStream);

                if (options.Ddict != IntPtr.Zero)
                {
                    ZSTD_DCtx_refDDict(dStream, options.Ddict).EnsureZstdSuccess();
                }
            }

            this.bufferSize = bufferSize > 0 ? bufferSize : (int)ZSTD_DStreamInSize().EnsureZstdSuccess();
            inputBuffer     = ArrayPool <byte> .Shared.Rent(this.bufferSize);

#if !(NET45 || NETSTANDARD2_0)
            inputMemory = new Memory <byte>(inputBuffer, 0, this.bufferSize);
#endif
            pos = size = (UIntPtr)this.bufferSize;
        }