Ionic Zip Library v1.9.1.6
InitializeDeflate Method
Reference ► Ionic.Zlib ► ZlibCodec ► InitializeDeflate()()()()
Initialize the ZlibCodec for deflation operation.


Z_OK if all goes well. You generally don't need to check the return code.

The codec will use the MAX window bits and the default level of compression.


int bufferSize = 40000; byte[] CompressedBytes = new byte[bufferSize]; byte[] DecompressedBytes = new byte[bufferSize]; ZlibCodec compressor = new ZlibCodec(); compressor.InitializeDeflate(CompressionLevel.Default); compressor.InputBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(TextToCompress); compressor.NextIn = 0; compressor.AvailableBytesIn = compressor.InputBuffer.Length; compressor.OutputBuffer = CompressedBytes; compressor.NextOut = 0; compressor.AvailableBytesOut = CompressedBytes.Length; while (compressor.TotalBytesIn != TextToCompress.Length && compressor.TotalBytesOut < bufferSize) { compressor.Deflate(FlushType.None); } while (true) { int rc= compressor.Deflate(FlushType.Finish); if (rc == ZlibConstants.Z_STREAM_END) break; } compressor.EndDeflate();