Ejemplo n.º 1
0
        public static byte[] CompressDirectory(string sInDir)
        {
            string[]     files        = Directory.GetFiles(sInDir, "*.*", SearchOption.AllDirectories);
            int          startIndex   = (sInDir[sInDir.Length - 1] != Path.DirectorySeparatorChar) ? (sInDir.Length + 1) : sInDir.Length;
            MemoryStream memoryStream = new MemoryStream();

            using (GZipStream zipStream = new GZipStream(memoryStream, CompressionMode.Compress))
            {
                string[] array = files;
                foreach (string text in array)
                {
                    string sRelativePath = text.Substring(startIndex);
                    ZIPHelper.CompressFile(sInDir, sRelativePath, zipStream);
                }
            }
            return(memoryStream.ToArray());
        }
Ejemplo n.º 2
0
        public static void CompressDirectory(string sInDir, string sOutFile)
        {
            string[] files      = Directory.GetFiles(sInDir, "*.*", SearchOption.AllDirectories);
            int      startIndex = (sInDir[sInDir.Length - 1] != Path.DirectorySeparatorChar) ? (sInDir.Length + 1) : sInDir.Length;

            using (FileStream compressedStream = new FileStream(sOutFile, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                using (GZipStream zipStream = new GZipStream(compressedStream, CompressionMode.Compress))
                {
                    string[] array = files;
                    foreach (string text in array)
                    {
                        string sRelativePath = text.Substring(startIndex);
                        ZIPHelper.CompressFile(sInDir, sRelativePath, zipStream);
                    }
                }
            }
        }