Deflate one batch of data.
Declaration Syntax
C# | C# | Visual Basic | Visual Basic | Visual C++ | Visual C++ | F# | F# |
public int Deflate( FlushType flush )
public int Deflate( FlushType flush )
Public Function Deflate ( flush As FlushType ) As Integer
Public Function Deflate ( flush As FlushType ) As Integer
public: int Deflate( FlushType flush )
public: int Deflate( FlushType flush )
member Deflate : flush : FlushType -> int
member Deflate : flush : FlushType -> int
Parameters
- flush (FlushType)
- whether to flush all data as you deflate. Generally you will want to use Z_NO_FLUSH here, in a series of calls to Deflate(), and then call EndDeflate() to flush everything.
Return Value
Int32
Z_OK if all goes well.
Z_OK if all goes well.
Remarks
You must have set InputBuffer and OutputBuffer before calling this method.
Examples
Copy | |
---|---|
private void DeflateBuffer(CompressionLevel level) { int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; ZlibCodec compressor = new ZlibCodec(); Console.WriteLine("\n============================================"); Console.WriteLine("Size of Buffer to Deflate: {0} bytes.", UncompressedBytes.Length); MemoryStream ms = new MemoryStream(); int rc = compressor.InitializeDeflate(level); compressor.InputBuffer = UncompressedBytes; compressor.NextIn = 0; compressor.AvailableBytesIn = UncompressedBytes.Length; compressor.OutputBuffer = buffer; // pass 1: deflate do { compressor.NextOut = 0; compressor.AvailableBytesOut = buffer.Length; rc = compressor.Deflate(FlushType.None); if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END) throw new Exception("deflating: " + compressor.Message); ms.Write(compressor.OutputBuffer, 0, buffer.Length - compressor.AvailableBytesOut); } while (compressor.AvailableBytesIn > 0 || compressor.AvailableBytesOut == 0); // pass 2: finish and flush do { compressor.NextOut = 0; compressor.AvailableBytesOut = buffer.Length; rc = compressor.Deflate(FlushType.Finish); if (rc != ZlibConstants.Z_STREAM_END && rc != ZlibConstants.Z_OK) throw new Exception("deflating: " + compressor.Message); if (buffer.Length - compressor.AvailableBytesOut > 0) ms.Write(buffer, 0, buffer.Length - compressor.AvailableBytesOut); } while (compressor.AvailableBytesIn > 0 || compressor.AvailableBytesOut == 0); compressor.EndDeflate(); ms.Seek(0, SeekOrigin.Begin); CompressedBytes = new byte[compressor.TotalBytesOut]; ms.Read(CompressedBytes, 0, CompressedBytes.Length); } |
Assembly: Keyoti.RapidSpell.NET4 (Module: Keyoti.RapidSpell.NET4.dll) Version: 6.2.21.412