Recurity.Swf.CwsFile.Compress C# (CSharp) Method

Compress() public method

public Compress ( Stream input ) : byte[]
input Stream
return byte[]
        public byte[] Compress(Stream input)
        {
            String s = String.Format("Compressing output with level {0:d}", CompressionLevel);
            //Log.Debug(this, s);

            Deflater deflater = new Deflater(CompressionLevel, false);
            byte[] uncompressedData = new byte[(Int32)input.Length];
            input.Seek(0, SeekOrigin.Begin);
            input.Read(uncompressedData, 0, uncompressedData.Length);
            byte[] buffer = new byte[input.Length];

            try
            {
                deflater.SetInput(uncompressedData);
                deflater.Finish();
                int bytesDeflated = deflater.Deflate(buffer, 0, buffer.Length);

                byte[] compressedData = new byte[bytesDeflated];
                Array.Copy(buffer, compressedData, bytesDeflated);

                //Log.Debug(this, "Compression completed.");

                return compressedData;
            }
            catch (Exception e)
            {
                Log.Error(this, e);
                throw e;
            }
        }