Esempio n. 1
0
        protected DeflateStream(Stream baseStream, ZLibDecompressOptions decompOpts, Format format)
        {
            ZLibInit.Manager.EnsureLoaded();

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

            // Check and set decompress options
            _leaveOpen  = decompOpts.LeaveOpen;
            _bufferSize = CheckBufferSize(decompOpts.BufferSize);
            _workBuf    = new byte[_bufferSize];
            int windowBits = CheckFormatWindowBits(decompOpts.WindowBits, _mode, format);

            // 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.InflateInit(_zs32, windowBits);
                ZLibException.CheckReturnValue(ret, _zs32);
                break;
            }

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

                ZLibRet ret = ZLibInit.Lib.L64.InflateInit(_zs64, windowBits);
                ZLibException.CheckReturnValue(ret, _zs64);
                break;
            }

            default:
                throw new PlatformNotSupportedException();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Create decompressing DeflateStream.
 /// </summary>
 public DeflateStream(Stream baseStream, ZLibDecompressOptions decompOpts)
     : this(baseStream, decompOpts, Format.Deflate)
 {
 }