public static void SaveZipFile(string sZipFileName, string sProtectPassword, params CNamePathPair[] apFileNames) { int num; using (ZipOutputStream zipOutputStream = new ZipOutputStream(File.Create(sZipFileName))) { if (sProtectPassword != null && sProtectPassword.Length > 0) { zipOutputStream.Password = sProtectPassword; } zipOutputStream.SetLevel(9); byte[] numArray = new byte[4096]; CNamePathPair[] cNamePathPairArray = apFileNames; for (int i = 0; i < (int)cNamePathPairArray.Length; i++) { CNamePathPair cNamePathPair = cNamePathPairArray[i]; ZipEntry zipEntry = new ZipEntry(cNamePathPair.Name) { DateTime = DateTime.Now }; zipOutputStream.PutNextEntry(zipEntry); using (FileStream fileStream = File.OpenRead(cNamePathPair.Path)) { do { num = fileStream.Read(numArray, 0, (int)numArray.Length); zipOutputStream.Write(numArray, 0, num); }while (num > 0); } } zipOutputStream.Finish(); zipOutputStream.Close(); } }
public static void CompressFileList(string sZipFileName, string[] asFileNameBuffer) { CNamePathPair[] cNamePathPairArray = new CNamePathPair[(int)asFileNameBuffer.Length]; for (int i = 0; i < (int)asFileNameBuffer.Length; i++) { CNamePathPair cNamePathPair = new CNamePathPair(i.ToString(), asFileNameBuffer[i]); cNamePathPairArray[i] = cNamePathPair; } Compression.SaveZipFile(sZipFileName, cNamePathPairArray); }
public static void SaveZipFile(string sFileName, string sDirPathToCompress) { string[] files = Directory.GetFiles(sDirPathToCompress); CNamePathPair[] cNamePathPair = new CNamePathPair[(int)files.Length]; for (int i = 0; i < (int)files.Length; i++) { cNamePathPair[i] = new CNamePathPair(Path.GetFileName(files[i]), files[i]); } Compression.SaveZipFile(sFileName, cNamePathPair); }