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

SetInput() public method

Sets the data which should be compressed next. This should be only called when needsInput indicates that more input is needed. If you call setInput when needsInput() returns false, the previous input that is still pending will be thrown away. The given byte array should not be changed, before needsInput() returns true again. This call is equivalent to setInput(input, 0, input.length).
/// if the buffer was finished() or ended(). ///
public SetInput ( byte input ) : void
input byte /// the buffer containing the input data. ///
return void
        public void SetInput(byte[] input)
        {
            SetInput(input, 0, input.Length);
        }

Same methods

Deflater::SetInput ( byte input, int offset, int count ) : void

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::SetInput