123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
-
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using ICSharpCode.SharpZipLib.Zip;
- namespace WPFTestUpdate.Compress
- {
-
-
-
- class CompressT
- {
-
-
-
-
-
- public static void Compress(string basePath, string source, ZipOutputStream s, CompressArgs args)
- {
- string[] filenames = Directory.GetFileSystemEntries(source);
- foreach (string file in filenames)
- {
- if (Directory.Exists(file))
- {
- Compress(basePath, file, s, args);
- }
- else
- {
- using (FileStream fs = File.OpenRead(file))
- {
- byte[] buffer = new byte[4 * 1024];
- ZipEntry entry = new ZipEntry(file.Replace(basePath, ""));
- entry.DateTime = DateTime.Now;
- s.PutNextEntry(entry);
- int sourceBytes;
- do
- {
- sourceBytes = fs.Read(buffer, 0, buffer.Length);
- s.Write(buffer, 0, sourceBytes);
- args.IncrementTransferred = sourceBytes;
- } while (sourceBytes > 0);
- }
- }
- }
- }
- }
- }
|