Пример #1
0
        /// <summary>
        /// 打包文件夹
        /// </summary>
        /// <param name="TarFile"></param>
        /// <param name="Dirs"></param>
        public void SerDirZip(string TarFile, params string[] Dirs)
        {
            GZipStream CompressedStream = null;//压缩流
            FileStream SerFile          = new FileStream(TarFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            try
            {
                CompressedStream = new GZipStream(SerFile, CompressionMode.Compress, true);
                CommpressTar ct = new CommpressTar();
                ct.SerDirToTar(CompressedStream, Dirs);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (CompressedStream != null)
                {
                    CompressedStream.Close();
                }

                if (SerFile != null)
                {
                    SerFile.Close();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 打包文件夹
        /// </summary>
        /// <param name="TarFile"></param>
        /// <param name="Dirs"></param>
        public void SerDirZip(string TarFile, string dir)
        {
            IO.FileHelper.DeleteFile(TarFile);
            FileStream       fs = new FileStream(TarFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            GZipOutputStream gzipoutputstream = new GZipOutputStream(fs);

            try
            {
                CommpressTar ct = new CommpressTar();
                ct.SerDirToTar(gzipoutputstream, dir);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (gzipoutputstream != null)
                {
                    gzipoutputstream.Close();
                }

                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 压缩文件
        /// </summary>
        /// <param name="filepath">源文件</param>
        /// <param name="dir">目标目录</param>
        /// <returns></returns>
        public void SerFileZip(string TargetFile, params string[] sourceFiles)
        {
            //FileStream SourceFileStream = null;
            GZipStream CompressedStream = null;//压缩流
            FileStream SerFile          = new FileStream(TargetFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            try
            {
                Console.WriteLine("目标文件:" + TargetFile);
                string       rootPath = System.IO.Path.GetDirectoryName(TargetFile);
                CommpressTar ctar     = new CommpressTar();

                CompressedStream = new GZipStream(SerFile, CompressionMode.Compress, true);

                ctar.SerFilesToTar(CompressedStream, rootPath, sourceFiles);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (CompressedStream != null)
                {
                    CompressedStream.Close();
                }

                if (SerFile != null)
                {
                    SerFile.Close();
                }
            }
        }