IdeaBlade DevForce 2010 Help Reference
Deflate Method
See Also  Example Send Feedback
IdeaBlade.Core Assembly > Ionic.Zlib Namespace > ZlibCodec Class : Deflate Method



flush
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.
Deflate one batch of data.

Syntax

Visual Basic (Declaration) 
Public Function Deflate( _
   ByVal flush As FlushType _
) As Integer
Visual Basic (Usage)Copy Code
Dim instance As ZlibCodec
Dim flush As FlushType
Dim value As Integer
 
value = instance.Deflate(flush)
C# 
public int Deflate( 
   FlushType flush
)
C++/CLI 
public:
int Deflate( 
   FlushType flush
) 

Parameters

flush
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

Z_OK if all goes well.

Example

C#Copy Code
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);
}

Remarks

You must have set InputBuffer and OutputBuffer before calling this method.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.