コード例 #1
0
		/// <summary>
		/// compress a directory
		/// </summary>
		/// <param name="archive"></param>
		/// <param name="directoryName"></param>
		public static void CompressDirectory(ZipFileInfo archive, string directoryName)
		{
			using (var zip = new ZipFile(Encoding.UTF8))
			{
				SetZipFile(zip, archive);
				zip.AddDirectory(directoryName);
				zip.Save(archive.Filename);
			}
		}
コード例 #2
0
		/// <summary>
		/// update archive file to use file or directory as item 
		/// </summary>
		/// <param name="existingArchive"></param>
		/// <param name="addFileOrDirectory"></param>
		/// <param name="directoryPathInArchive"></param>
		public static void UpdateArchiveItem(ZipFileInfo existingArchive, string addFileOrDirectory, string directoryPathInArchive)
		{
			using (var zip = ZipFile.Read(existingArchive.Filename))
			{
				zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
				zip.UpdateItem(addFileOrDirectory, directoryPathInArchive);
				zip.Save();
			}
		}
コード例 #3
0
		private static void SetZipFile(ZipEntry zipEntry, ZipFileInfo file)
		{
			if (!string.IsNullOrEmpty(file.Password))
				zipEntry.Password = file.Password;

			zipEntry.Comment = file.Comment;
			zipEntry.CompressionMethod = (Ionic.Zip.CompressionMethod)((int)file.CompressionMethod);
			zipEntry.CompressionLevel = (Ionic.Zlib.CompressionLevel)((int)file.CompressionLevel);
		}
コード例 #4
0
 /// <summary>
 /// compress a directory
 /// </summary>
 /// <param name="archive"></param>
 /// <param name="directoryName"></param>
 public static void CompressDirectory(ZipFileInfo archive, string directoryName)
 {
     using (var zip = new ZipFile(Encoding.UTF8))
     {
         SetZipFile(zip, archive);
         zip.AddDirectory(directoryName);
         zip.Save(archive.Filename);
     }
 }
コード例 #5
0
 /// <summary>
 /// update archive file to use file or directory as item
 /// </summary>
 /// <param name="existingArchive"></param>
 /// <param name="addFileOrDirectory"></param>
 /// <param name="directoryPathInArchive"></param>
 public static void UpdateArchiveItem(ZipFileInfo existingArchive, string addFileOrDirectory, string directoryPathInArchive)
 {
     using (var zip = ZipFile.Read(existingArchive.Filename))
     {
         zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
         zip.UpdateItem(addFileOrDirectory, directoryPathInArchive);
         zip.Save();
     }
 }
コード例 #6
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="existingArchive"></param>
		/// <param name="filePathInArchive"></param>
		/// <returns></returns>
		public static bool ExistItemInArchive(ZipFileInfo existingArchive, string filePathInArchive)
		{
			using (var zip = ZipFile.Read(existingArchive.Filename))
			{
				zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
				var entryQuery = zip.Entries.Where(o => o.FileName.Equals(filePathInArchive));
				if (!entryQuery.Any()) return false;
				return true;
			}
		}
コード例 #7
0
        private static void SetZipFile(ZipEntry zipEntry, ZipFileInfo file)
        {
            if (!string.IsNullOrEmpty(file.Password))
            {
                zipEntry.Password = file.Password;
            }

            zipEntry.Comment           = file.Comment;
            zipEntry.CompressionMethod = (Ionic.Zip.CompressionMethod)((int)file.CompressionMethod);
            zipEntry.CompressionLevel  = (Ionic.Zlib.CompressionLevel)((int)file.CompressionLevel);
        }
コード例 #8
0
        /// <summary>
        /// compress a file to archive file
        /// </summary>
        /// <param name="archive"></param>
        /// <param name="directoryName"></param>
        /// <param name="directoryPathInArchive"></param>
        public static void CompressAndSpecifyPathArchive(ZipFileInfo archive, string directoryName, string directoryPathInArchive)
        {
            using (var zip = new ZipFile(Encoding.UTF8))
            {
                SetZipFile(zip, archive);
                ZipEntry entry = zip.AddDirectory(directoryName, directoryPathInArchive);

                SetZipFile(entry, archive);
                zip.Save(archive.Filename);
            }
        }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="archive"></param>
        /// <param name="stream"></param>
        /// <param name="streamFile"></param>
        public static void AddStreamToArchive(ZipFileInfo archive, ZipFileInfo streamFile, Stream stream)
        {
            using (var zip = new ZipFile(Encoding.UTF8))
            {
                SetZipFile(zip, archive);
                ZipEntry entry = zip.AddEntry(streamFile.Filename, stream);

                SetZipFile(entry, streamFile);
                zip.Save(archive.Filename);
            }
        }
コード例 #10
0
		/// <summary>
		/// compress any files
		/// </summary>
		/// <param name="archive"></param>
		/// <param name="fileInfos"></param>
		public static void CompressFile(ZipFileInfo archive, List<ZipFileInfo> fileInfos, string directoryPathInArchive)
		{
			using (var zip = new ZipFile(Encoding.UTF8))
			{
				SetZipFile(zip, archive);
				foreach (var file in fileInfos)
				{
					SetZipFile(zip, file);
					zip.AddFile(file.Filename, directoryPathInArchive);
				}
				zip.Save(archive.Filename);
			}
		}
コード例 #11
0
 /// <summary>
 /// compress any files
 /// </summary>
 /// <param name="archive"></param>
 /// <param name="fileInfos"></param>
 public static void CompressFile(ZipFileInfo archive, List <ZipFileInfo> fileInfos, string directoryPathInArchive)
 {
     using (var zip = new ZipFile(Encoding.UTF8))
     {
         SetZipFile(zip, archive);
         foreach (var file in fileInfos)
         {
             SetZipFile(zip, file);
             zip.AddFile(file.Filename, directoryPathInArchive);
         }
         zip.Save(archive.Filename);
     }
 }
コード例 #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="existingArchive"></param>
 /// <param name="filePathInArchive"></param>
 /// <returns></returns>
 public static bool ExistItemInArchive(ZipFileInfo existingArchive, string filePathInArchive)
 {
     using (var zip = ZipFile.Read(existingArchive.Filename))
     {
         zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
         var entryQuery = zip.Entries.Where(o => o.FileName.Equals(filePathInArchive));
         if (!entryQuery.Any())
         {
             return(false);
         }
         return(true);
     }
 }
コード例 #13
0
		/// <summary>
		/// compress a file to archive file
		/// </summary>
		/// <param name="archive"></param>
		/// <param name="directoryName"></param>
		/// <param name="directoryPathInArchive"></param>
		public static void CompressAndSpecifyPathArchive(ZipFileInfo archive, string directoryName, string directoryPathInArchive)
		{
			using (var zip = new ZipFile(Encoding.UTF8))
			{
				SetZipFile(zip, archive);
				ZipEntry entry = zip.AddDirectory(directoryName, directoryPathInArchive);

				SetZipFile(entry, archive);
				zip.Save(archive.Filename);
			}
		}
コード例 #14
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="archive"></param>
		/// <param name="stream"></param>
		/// <param name="streamFile"></param>
		public static void AddStreamToArchive(ZipFileInfo archive, ZipFileInfo streamFile, Stream stream)
		{
			using (var zip = new ZipFile(Encoding.UTF8))
			{
				SetZipFile(zip, archive);
				ZipEntry entry = zip.AddEntry(streamFile.Filename, stream);

				SetZipFile(entry, streamFile);
				zip.Save(archive.Filename);
			}
		}