WordHelper/ZipHelper.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using System;
using System.IO;

namespace WordHelper
{
	public class ZipHelper
	{
		public static void CreateZip(string sourceFilePath, string destinationZipFilePath)
		{
			if (sourceFilePath[sourceFilePath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
			{
				sourceFilePath += System.IO.Path.DirectorySeparatorChar;
			}
			ZipOutputStream zipStream = new ZipOutputStream(System.IO.File.Create(destinationZipFilePath));
			zipStream.SetLevel(6);
			ZipHelper.CreateZipFiles(sourceFilePath, zipStream, sourceFilePath);
			zipStream.Finish();
			zipStream.Close();
		}

		private static void CreateZipFiles(string sourceFilePath, ZipOutputStream zipStream, string staticFile)
		{
			Crc32 crc = new Crc32();
			string[] filesArray = System.IO.Directory.GetFileSystemEntries(sourceFilePath);
			string[] array = filesArray;
			for (int i = 0; i < array.Length; i++)
			{
				string file = array[i];
				if (System.IO.Directory.Exists(file))
				{
					ZipHelper.CreateZipFiles(file, zipStream, staticFile);
				}
				else
				{
					System.IO.FileStream fileStream = System.IO.File.OpenRead(file);
					byte[] buffer = new byte[fileStream.Length];
					fileStream.Read(buffer, 0, buffer.Length);
					string tempFile = file.Substring(staticFile.LastIndexOf("\\") + 1);
					ZipEntry entry = new ZipEntry(tempFile);
					entry.DateTime = System.DateTime.Now;
					entry.Size = fileStream.Length;
					fileStream.Close();
					crc.Reset();
					crc.Update(buffer);
					entry.Crc = crc.Value;
					zipStream.PutNextEntry(entry);
					zipStream.Write(buffer, 0, buffer.Length);
				}
			}
		}

		public static void CreateZipFiles(string[] filesArray, string destinationZipFilePath)
		{
			Crc32 crc = new Crc32();
			ZipOutputStream zipStream = new ZipOutputStream(System.IO.File.Create(destinationZipFilePath));
			zipStream.SetLevel(6);
			for (int i = 0; i < filesArray.Length; i++)
			{
后面还有 23 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。