示例#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();
            }
        }
示例#2
0
        public CompressorStream(Stream stream, CompressionOptions options)
        {
            InnerStream = stream;
            Options     = options;
            CStream     = ZSTD_createCStream();
            if (options.Cdict == IntPtr.Zero)
            {
                ZSTD_initCStream(CStream, options.CompressionLevel).EnsureZstdSuccess();
            }
            else
            {
                ZSTD_initCStream_usingCDict(CStream, options.Cdict).EnsureZstdSuccess();
            }

            OutputBuffer = CreateOutputBuffer();
            InitializedOutputBufferState();
        }
示例#3
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
        }
示例#4
0
        public Compressor(CompressionOptions options)
        {
            Options = options;

            cctx = ExternMethods.ZSTD_createCCtx().EnsureZstdSuccess();
        }
示例#5
0
 internal Compressor(ZstdNet.CompressionOptions options) => Delegator = new(options);
        public StreamingCompressor(CompressionOptions options)
        {
            Options = options;

            zcs = ExternMethods.ZSTD_createCStream().EnsureZstdSuccess();
        }