Ejemplo n.º 1
0
        public Compressor(CompressionOptions options)
        {
            Options = options;
            cctx    = ExternMethods.ZSTD_createCCtx().EnsureZstdSuccess();

            options.ApplyCompressionParams(cctx);

            if (options.Cdict != IntPtr.Zero)
            {
                ExternMethods.ZSTD_CCtx_refCDict(cctx, options.Cdict).EnsureZstdSuccess();
            }
        }
Ejemplo n.º 2
0
        public CompressionStream(Stream stream, CompressionOptions options, int bufferSize = 0)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (!stream.CanWrite)
            {
                throw new ArgumentException("Stream is not writable", nameof(stream));
            }
            if (bufferSize < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferSize));
            }

            innerStream = stream;

            cStream = ZSTD_createCStream().EnsureZstdSuccess();
            ZSTD_CCtx_reset(cStream, ZSTD_ResetDirective.ZSTD_reset_session_only).EnsureZstdSuccess();

            if (options != null)
            {
                options.ApplyCompressionParams(cStream);

                if (options.Cdict != IntPtr.Zero)
                {
                    ZSTD_CCtx_refCDict(cStream, options.Cdict).EnsureZstdSuccess();
                }
            }

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

#if !(NET45 || NETSTANDARD2_0)
            outputMemory = new ReadOnlyMemory <byte>(outputBuffer, 0, this.bufferSize);
#endif
        }