예제 #1
0
        protected DeflateStream(Stream baseStream, ZLibCompressOptions compOpts, Format format)
        {
            ZLibInit.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];
            int formatWindowBits = CheckFormatWindowBits(compOpts.WindowBits, _mode, format);

            CheckMemLevel(compOpts.MemLevel);

            // Prepare and init ZStream
            switch (ZLibInit.Lib.PlatformLongSize)
            {
            case PlatformLongSize.Long32:
            {
                _zs32  = new ZStreamL32();
                _zsPin = GCHandle.Alloc(_zs32, GCHandleType.Pinned);

                ZLibRet ret = ZLibInit.Lib.L32.DeflateInit(_zs32, compOpts.Level, formatWindowBits, compOpts.MemLevel);
                ZLibException.CheckReturnValue(ret, _zs32);
                break;
            }

            case PlatformLongSize.Long64:
            {
                _zs64  = new ZStreamL64();
                _zsPin = GCHandle.Alloc(_zs64, GCHandleType.Pinned);

                ZLibRet ret = ZLibInit.Lib.L64.DeflateInit(_zs64, compOpts.Level, formatWindowBits, compOpts.MemLevel);
                ZLibException.CheckReturnValue(ret, _zs64);
                break;
            }

            default:
                throw new PlatformNotSupportedException();
            }
        }
예제 #2
0
            internal ZLibRet InflateInit(ZStreamL32 strm, int windowBits)
            {
                string zlibVer = Lib.ZLibVersion();

                return(InflateInit2(strm, windowBits, zlibVer, Marshal.SizeOf <ZStreamL32>()));
            }