private unsafe void RawWrite(byte *buffer, byte *pOutput, int count) { #if DEBUG fixed(byte *bufferPointer = &_buffer[0]) { Contracts.Assert(pOutput == bufferPointer); } #endif Constants.RetCode ret; _zstrm.AvailIn = (uint)count; _zstrm.NextIn = buffer; _zstrm.NextOut = pOutput + BufferUsed; do { RefreshOutput(pOutput); fixed(ZStream *pZstream = &_zstrm) { ret = Zlib.deflate(pZstream, Constants.Flush.NoFlush); } if (ret != Constants.RetCode.OK) { throw Contracts.Except("Zlib.deflate failed with {0}", ret); } } while (_zstrm.AvailIn > 0); _zstrm.NextIn = null; }
protected override void Dispose(bool disposing) { if (_disposed) { return; } _disposed = true; Constants.RetCode disposeRet = Constants.RetCode.StreamEnd; if (disposing) { unsafe { fixed(byte *pOutput = _buffer) fixed(ZStream * pZstream = &_zstrm) { pZstream->AvailIn = 0; pZstream->NextIn = null; pZstream->NextOut = pOutput + BufferUsed; do { RefreshOutput(pOutput); disposeRet = Zlib.deflate(pZstream, Constants.Flush.Finish); } while (disposeRet == Constants.RetCode.OK); if (disposeRet == Constants.RetCode.StreamEnd) { Flush(); _compressed.Flush(); } } } } Constants.RetCode ret; unsafe { fixed(ZStream *pZstream = &_zstrm) { ret = Zlib.deflateEnd(pZstream); } } base.Dispose(disposing); if (disposing) { GC.SuppressFinalize(this); if (disposeRet != Constants.RetCode.StreamEnd) { throw Contracts.Except("Zlib deflate failed with {0}", disposeRet); } if (ret != Constants.RetCode.OK) { throw Contracts.Except("Zlib deflateEnd failed with {0}", ret); } } }