ICSharpCode.SharpZipLib.Zip.Compression.Deflater.Deflate C# (CSharp) Method

Deflate() public method

Deflates the current input block with to the given array.
public Deflate ( byte output ) : int
output byte /// The buffer where compressed data is stored ///
return int
        public int Deflate(byte[] output)
        {
            return Deflate(output, 0, output.Length);
        }

Same methods

Deflater::Deflate ( byte output, int offset, int length ) : int

Usage Example

Example #1
1
        public byte[] Compress(byte[] input)
        {
            // Create the compressor with highest level of compression
            Deflater compressor = new Deflater();
            compressor.SetLevel(Deflater.BEST_COMPRESSION);

            // Give the compressor the data to compress
            compressor.SetInput(input);
            compressor.Finish();

            /*
             * Create an expandable byte array to hold the compressed data.
             * You cannot use an array that's the same size as the orginal because
             * there is no guarantee that the compressed data will be smaller than
             * the uncompressed data.
             */
            MemoryStream bos = new MemoryStream(input.Length);

            // Compress the data
            byte[] buf = new byte[1024];
            while (!compressor.IsFinished)
            {
                int count = compressor.Deflate(buf);
                bos.Write(buf, 0, count);
            }

            // Get the compressed data
            return bos.ToArray();
        }
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.Compression.Deflater::Deflate