APG.CodeHelper.CompressionHelper.CompressOrDecompressFile C# (CSharp) Метод

CompressOrDecompressFile() приватный статический Метод

Компрессия или декомпрессия файла
private static CompressOrDecompressFile ( string fromFile, string toFile, System compressionMode ) : void
fromFile string Исходный файл для компрессии или декомпрессии
toFile string Целевой файл
compressionMode System Указывает на компрессию или декомпрессию
Результат void
        private static void CompressOrDecompressFile(string fromFile, string toFile, System.IO.Compression.CompressionMode compressionMode)
        {
            System.IO.FileStream toFs = null;
            System.IO.Compression.GZipStream gzStream = null;
            System.IO.FileStream fromFs = new System.IO.FileStream(fromFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            try
            {
                toFs = new System.IO.FileStream(toFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                gzStream = new System.IO.Compression.GZipStream(toFs, compressionMode);
                byte[] buf = new byte[fromFs.Length];
                fromFs.Read(buf, 0, buf.Length);
                gzStream.Write(buf, 0, buf.Length);
            }
            finally
            {
                if (gzStream != null)
                    gzStream.Close();

                if (toFs != null)
                    toFs.Close();

                fromFs.Close();
            }
        }