/// <summary>Initializes a new instance of the GZipStream class using the specified stream and BZip2CompressionMode value.</summary> /// <param name="stream">The stream to compress or decompress.</param> /// <param name="mode">One of the BZip2CompressionMode values that indicates the action to take.</param> /// <param name="options">The Gzip Options</param>ll public unsafe GZipStream(Stream stream, CompressionMode mode, GZipOptions options) { if (stream == null) { throw new ArgumentNullException("stream"); } _stream = stream; _mode = mode; _zstream.zalloc = null; _zstream.zfree = null; _zstream.opaque = null; _tmpBuffer = new byte[BufferSize]; _tmpBufferHandle = GCHandle.Alloc(_tmpBuffer, GCHandleType.Pinned); _tmpBufferPtr = _tmpBufferHandle.AddrOfPinnedObject().ToPointer(); ZLibReturnCode ret; switch (mode) { case CompressionMode.Compress: ret = ZLibNative.deflateInit2_(ref _zstream, options.Level, options.Method, options.WindowBits, options.MemoryLevel, (int)options.Strategy, ZLibVersion, Marshal.SizeOf(typeof(ZStream))); if (ret != ZLibReturnCode.Ok) { throw new ArgumentException("Unable to init ZLib. Return code: " + ret); } _zstream.next_out = (byte *)_tmpBufferPtr; _zstream.avail_out = (uint)_tmpBuffer.Length; break; case CompressionMode.Decompress: ret = ZLibNative.inflateInit2_(ref _zstream, options.WindowBits, ZLibVersion, Marshal.SizeOf(typeof(ZStream))); if (ret != ZLibReturnCode.Ok) { throw new ArgumentException("Unable to init ZLib. Return code: " + ret); } break; } }
/// <summary>Initializes a new instance of the GZipStream class using the specified stream and BZip2CompressionMode value.</summary> /// <param name="stream">The stream to compress or decompress.</param> /// <param name="mode">One of the BZip2CompressionMode values that indicates the action to take.</param> /// <param name="options">The Gzip Options</param>ll public unsafe GZipStream(Stream stream, CompressionMode mode, GZipOptions options) { if (stream == null) throw new ArgumentNullException("stream"); _stream = stream; _mode = mode; _zstream.zalloc = null; _zstream.zfree = null; _zstream.opaque = null; _tmpBuffer = new byte[BufferSize]; _tmpBufferHandle = GCHandle.Alloc(_tmpBuffer, GCHandleType.Pinned); _tmpBufferPtr = _tmpBufferHandle.AddrOfPinnedObject().ToPointer(); ZLibReturnCode ret; switch (mode) { case CompressionMode.Compress: ret = ZLibNative.deflateInit2_(ref _zstream, options.Level, options.Method, options.WindowBits, options.MemoryLevel, (int) options.Strategy, ZLibVersion, Marshal.SizeOf(typeof(ZStream))); if (ret != ZLibReturnCode.Ok) throw new ArgumentException("Unable to init ZLib. Return code: " + ret); _zstream.next_out = (byte*) _tmpBufferPtr; _zstream.avail_out = (uint) _tmpBuffer.Length; break; case CompressionMode.Decompress: ret = ZLibNative.inflateInit2_(ref _zstream, options.WindowBits, ZLibVersion, Marshal.SizeOf(typeof(ZStream))); if (ret != ZLibReturnCode.Ok) throw new ArgumentException("Unable to init ZLib. Return code: " + ret); break; } }