当前位置: 首页>>代码示例>>C#>>正文


C# Crc32.Update方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Checksums.Crc32.Update方法的典型用法代码示例。如果您正苦于以下问题:C# Crc32.Update方法的具体用法?C# Crc32.Update怎么用?C# Crc32.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Checksums.Crc32的用法示例。


在下文中一共展示了Crc32.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateFileZip

        /// <summary>
        /// 压缩文件
        /// </summary>
        /// <param name="sourceFilePath">待压缩的文件或文件夹路径</param>
        /// <param name="destinationZipFilePath">保存压缩文件的文件名</param>
        /// <param name="level">压缩文件等级</param>
        /// <returns>返回-2说明被压缩文件已经存在,返回1说明压缩成功</returns>            
        public static int CreateFileZip(string sourceFilePath, string destinationZipFilePath, int level)
        {
            if (!Directory.Exists(destinationZipFilePath.Substring(0, destinationZipFilePath.LastIndexOf("\\"))))
            {
                Directory.CreateDirectory(destinationZipFilePath.Substring(0, destinationZipFilePath.LastIndexOf("\\")));
            }
            if (File.Exists(destinationZipFilePath))
            {
                return -2;
            }
            else
            {
                ZipOutputStream zipStream = new ZipOutputStream(File.Create(destinationZipFilePath));
                zipStream.SetLevel(level);  // 压缩级别 0-9

                Crc32 crc = new Crc32();
                FileStream fileStream = File.OpenRead(sourceFilePath);
                byte[] buffer = new byte[fileStream.Length];
                fileStream.Read(buffer, 0, buffer.Length);
                string tempFile = sourceFilePath.Substring(sourceFilePath.LastIndexOf("\\") + 1);
                ZipEntry entry = new ZipEntry(tempFile);
                entry.DateTime = 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);

                zipStream.Finish();
                zipStream.Close();
                return 1;
            }
        }
开发者ID:yonglehou,项目名称:ToolRepository,代码行数:42,代码来源:ZipHelper.cs

示例2: CreateZipFile

        public void CreateZipFile(string[] straFilenames, string strOutputFilename)
        {
            Crc32 crc = new Crc32();
            ZipOutputStream zos = new ZipOutputStream(File.Create(strOutputFilename));

            zos.SetLevel(m_nCompressionLevel);

            foreach (string strFileName in straFilenames)
            {
                FileStream fs = File.OpenRead(strFileName);

                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                ZipEntry entry = new ZipEntry(GetFileNameWithoutDrive(strFileName));

                entry.DateTime = DateTime.Now;

                entry.Size = fs.Length;
                fs.Close();

                crc.Reset();
                crc.Update(buffer);

                entry.Crc  = crc.Value;

                zos.PutNextEntry(entry);

                zos.Write(buffer, 0, buffer.Length);
            }

            zos.Finish();
            zos.Close();
        }
开发者ID:tgiphil,项目名称:wintools,代码行数:33,代码来源:ZipCompressor.cs

示例3: Zip

 public static  void Zip(string strFile, string strZipFile)
 {
     Crc32 crc1 = new Crc32();
     ZipOutputStream stream1 = new ZipOutputStream(File.Create(strZipFile));
     try
     {
         stream1.SetLevel(6);
         FileStream stream2 = File.OpenRead(strFile);
         byte[] buffer1 = new byte[stream2.Length];
         stream2.Read(buffer1, 0, buffer1.Length);
         ZipEntry entry1 = new ZipEntry(strFile.Split(new char[] { '\\' })[strFile.Split(new char[] { '\\' }).Length - 1]);
         entry1.DateTime = DateTime.Now;
         entry1.Size = stream2.Length;
         stream2.Close();
         crc1.Reset();
         crc1.Update(buffer1);
         entry1.Crc = crc1.Value;
         stream1.PutNextEntry(entry1);
         stream1.Write(buffer1, 0, buffer1.Length);
     }
     catch (Exception exception1)
     {
         throw exception1;
     }
     finally
     {
         stream1.Finish();
         stream1.Close();
         stream1 = null;
         crc1 = null;
     }
 }
开发者ID:powerhai,项目名称:Jinchen,代码行数:32,代码来源:ZipHelper.cs

示例4: zip

 private void zip(string strFile, ZipOutputStream s, string staticFile)
 {
     if (strFile[strFile.Length - 1] != Path.DirectorySeparatorChar) strFile += Path.DirectorySeparatorChar;
     Crc32 crc = new Crc32();
     string[] filenames = Directory.GetFileSystemEntries(strFile);
     foreach (string file in filenames)
     {
         if (Directory.Exists(file))
         {
             zip(file, s, staticFile);
         }
         else // 否则直接压缩文件
         {
             //打开压缩文件
             FileStream fs = File.OpenRead(file);
             byte[] buffer = new byte[fs.Length];
             fs.Read(buffer, 0, buffer.Length);
             string tempfile = file.Substring(staticFile.LastIndexOf("\\") + 1);
             ZipEntry entry = new ZipEntry(tempfile);
             entry.DateTime = DateTime.Now;
             entry.Size = fs.Length;
             fs.Close();
             crc.Reset();
             crc.Update(buffer);
             entry.Crc = crc.Value;
             s.PutNextEntry(entry);
             s.Write(buffer, 0, buffer.Length);
         }
     }
 }
开发者ID:MasterKongKong,项目名称:eReim,代码行数:30,代码来源:ZipFloClass.cs

示例5: ZipFileDirectory

        private static void ZipFileDirectory(string[] files, ZipOutputStream z)
        {
            FileStream fs = null;
            Crc32 crc = new Crc32();
            try
            {
                foreach(string file in files)
                {
                    fs = File.OpenRead(file);
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    string fileName = Path.GetFileName(file);

                    ZipEntry entry = new ZipEntry(fileName);
                    entry.DateTime = DateTime.Now;
                    entry.Size = fs.Length;
                    fs.Close();
                    crc.Reset();
                    crc.Update(buffer);
                    entry.Crc = crc.Value;
                    z.PutNextEntry(entry);
                    z.Write(buffer, 0, buffer.Length);
                }
            }
            finally
            {
                if(fs!=null)
                {
                    fs.Close();
                    fs = null;
                }
                GC.Collect();
            }
        }
开发者ID:RoxieZ,项目名称:Internet-Programming,代码行数:34,代码来源:FileZipper.cs

示例6: CreateZipFiles

        /// <summary>
        /// 递归压缩文件
        /// </summary>
        /// <param name="sourceFilePath">待压缩的文件或文件夹路径</param>
        /// <param name="zipStream">打包结果的zip文件路径(类似 D:\WorkSpace\a.zip),全路径包括文件名和.zip扩展名</param>
        /// <param name="staticFile"></param>
        private static void CreateZipFiles(string sourceFilePath, ZipOutputStream zipStream, string staticFile)
        {
            Crc32 crc = new Crc32();
            string[] filesArray = Directory.GetFileSystemEntries(sourceFilePath);
            foreach (string file in filesArray)
            {
                if (Directory.Exists(file))                     //如果当前是文件夹,递归
                {
                    CreateZipFiles(file, zipStream, staticFile);
                }

                else                                            //如果是文件,开始压缩
                {
                    FileStream fileStream = 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 = 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);
                }
            }
        }
开发者ID:454240357,项目名称:SmartLaw,代码行数:38,代码来源:ZipHelper.cs

示例7: ZipDir

   /// <summary>
 /// 压缩文件夹
 /// </summary>
 /// <param name="dirToZip"></param>
 /// <param name="zipedFileName"></param>
 /// <param name="compressionLevel">压缩率0(无压缩)9(压缩率最高)</param>
 public void ZipDir(string dirToZip, string zipedFileName, int compressionLevel = 9)
 {
     if (Path.GetExtension(zipedFileName) != ".zip")
     {
         zipedFileName = zipedFileName + ".zip";
     }
     using (var zipoutputstream = new ZipOutputStream(File.Create(zipedFileName)))
     {
         zipoutputstream.SetLevel(compressionLevel);
         var crc = new Crc32();
         var fileList = GetAllFies(dirToZip);
         foreach (DictionaryEntry item in fileList)
         {
             var fs = new FileStream(item.Key.ToString(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
             var buffer = new byte[fs.Length];
             fs.Read(buffer, 0, buffer.Length);
             // ZipEntry entry = new ZipEntry(item.Key.ToString().Substring(dirToZip.Length + 1));
             var entry = new ZipEntry(Path.GetFileName(item.Key.ToString()))
                              {
                                  DateTime = (DateTime) item.Value,
                                  Size = fs.Length
                              };
             fs.Close();
             crc.Reset();
             crc.Update(buffer);
             entry.Crc = crc.Value;
             zipoutputstream.PutNextEntry(entry);
             zipoutputstream.Write(buffer, 0, buffer.Length);
         }
     }
 }
开发者ID:lizhi5753186,项目名称:QDF,代码行数:37,代码来源:ZipHelper.cs

示例8: AddZip

        public static string AddZip(string fileName, string zipName, ZipOutputStream s)
        {
            Crc32 crc = new Crc32();
            try
            {
                FileStream fs = File.OpenRead(fileName);
                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                fileName = Path.GetFileName(fileName);
                long fileLength = fs.Length;
                fs.Close();

                ZipEntry entry = new ZipEntry(zipName);
                entry.DateTime = DateTime.Now;
                entry.Size = fileLength;

                crc.Reset();
                crc.Update(buffer);
                entry.Crc = crc.Value;
                s.PutNextEntry(entry);
                s.Write(buffer, 0, buffer.Length);

                return string.Empty;
            }
            catch (Exception addEx)
            {
                return addEx.ToString();
            }
        }
开发者ID:hoya0,项目名称:sw,代码行数:29,代码来源:ZipClass.cs

示例9: AddStream

        public void AddStream(string fileName, Stream stream)
        {
            if (_zipOutputStream == null)
                _zipOutputStream = new ZipOutputStream(File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite));

            //
            // Create a CRC value that identifies the file
            //
            var crc = new Crc32();
            crc.Reset();
            crc.Update((int)stream.Length);

            //
            // Create a Zip Entry 
            //
            var zipEntry = new ZipEntry(fileName);
            zipEntry.DateTime = DateTime.Now;
            zipEntry.Size = stream.Length;
            zipEntry.Crc = crc.Value;

            //
            // Attach the Zip Entry in ZipFile
            //
            _zipOutputStream.PutNextEntry(zipEntry);
            Pump(stream, _zipOutputStream);
            _zipOutputStream.CloseEntry();
            _zipOutputStream.Flush();
        }
开发者ID:sidneylimafilho,项目名称:InfoControl,代码行数:28,代码来源:Compact.cs

示例10: ZipFile

        //public static void ZipFile(string path, string file2Zip, string zipFileName, string zip, string bldgType)
        public static void ZipFile(string path, string file2Zip, string zipFileName)
        {
            //MemoryStream ms = InitializeGbxml(path + file2Zip, zip, bldgType) as MemoryStream;
            MemoryStream ms = InitializeGbxml(Path.Combine(path , file2Zip)) as MemoryStream;
 
            string compressedFile =Path.Combine(path, zipFileName);
            if (File.Exists(compressedFile))
            {
                File.Delete(compressedFile);
            }
            Crc32 objCrc32 = new Crc32();
            ZipOutputStream strmZipOutputStream = new ZipOutputStream(File.Create(compressedFile));
            strmZipOutputStream.SetLevel(9);

            byte[] gbXmlBuffer = new byte[ms.Length];
            ms.Read(gbXmlBuffer, 0, gbXmlBuffer.Length);

            ZipEntry objZipEntry = new ZipEntry(file2Zip);

            objZipEntry.DateTime = DateTime.Now;
            objZipEntry.Size = ms.Length;
            ms.Close();
            objCrc32.Reset();
            objCrc32.Update(gbXmlBuffer);
            objZipEntry.Crc = objCrc32.Value;
            strmZipOutputStream.PutNextEntry(objZipEntry);
            strmZipOutputStream.Write(gbXmlBuffer, 0, gbXmlBuffer.Length);
            strmZipOutputStream.Finish();
            strmZipOutputStream.Close();
            strmZipOutputStream.Dispose();
        }
开发者ID:whztt07,项目名称:EnergyAnalysisForDynamo,代码行数:32,代码来源:ZipUtil.cs

示例11: RuntimeInfo

		public RuntimeInfo(CompressionMethod method, int compressionLevel, 
            int size, string password, bool getCrc)
		{
			this.method = method;
			this.compressionLevel = compressionLevel;
			this.password = password;
			this.size = size;
			this.random = false;

			original = new byte[Size];
			if (random) {
				System.Random rnd = new Random();
				rnd.NextBytes(original);
			}
			else {
				for (int i = 0; i < size; ++i) {
					original[i] = (byte)'A';
				}
			}

			if (getCrc) {
				Crc32 crc32 = new Crc32();
				crc32.Update(original, 0, size);
				crc = crc32.Value;
			}
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:26,代码来源:ZipTests.cs

示例12: AddZipEntryToZipOutputStream

        internal void AddZipEntryToZipOutputStream(ZipOutputStream zipOutputStream, string content, string zipEntryName)
		{
            byte[] xmlBytes = m_encoding.GetBytes(content);

			ZipEntry zipEntry = new ZipEntry(zipEntryName);

			zipEntry.Size = xmlBytes.Length;
			zipEntry.DateTime = DateTime.Now;

			Crc32 crc = new Crc32();
			crc.Reset();
			crc.Update(xmlBytes);
			zipEntry.Crc = crc.Value;

			zipOutputStream.PutNextEntry(zipEntry);
			zipOutputStream.Write(xmlBytes, 0, xmlBytes.Length);
			zipOutputStream.CloseEntry();
		}
开发者ID:killbug2004,项目名称:WSProf,代码行数:18,代码来源:PolicyFileWriter.cs

示例13: CalculateCRC32

        public static long CalculateCRC32(
            string theFileName)
        {
            using (FileStream theFileStream = File.OpenRead(theFileName))
            {
                Crc32 theCRC32Provider = new Crc32();

                byte[] theBuffer = new byte[theFileStream.Length];

                theFileStream.Read(theBuffer, 0, theBuffer.Length);

                theCRC32Provider.Reset();

                theCRC32Provider.Update(theBuffer);

                return theCRC32Provider.Value;
            }
        }
开发者ID:jzengerling,项目名称:karaokidex,代码行数:18,代码来源:IOOperations.cs

示例14: Compress

 public static bool Compress(string FileName, string ZipFileName)
 {
     ZipOutputStream stream;
     FileStream stream2;
     if (ZipFileName == "")
     {
         ZipFileName = FileName + ".zip";
     }
     Crc32 crc = new Crc32();
     try
     {
         stream = new ZipOutputStream(System.IO.File.Create(ZipFileName));
     }
     catch
     {
         return false;
     }
     stream.SetLevel(6);
     try
     {
         stream2 = System.IO.File.OpenRead(FileName);
     }
     catch
     {
         stream.Finish();
         stream.Close();
         System.IO.File.Delete(ZipFileName);
         return false;
     }
     byte[] buffer = new byte[stream2.Length];
     stream2.Read(buffer, 0, buffer.Length);
     ZipEntry entry = new ZipEntry(FileName.Split(new char[] { '\\' })[FileName.Split(new char[] { '\\' }).Length - 1]);
     entry.DateTime = DateTime.Now;
     entry.Size = stream2.Length;
     stream2.Close();
     crc.Reset();
     crc.Update(buffer);
     entry.Crc = crc.Value;
     stream.PutNextEntry(entry);
     stream.Write(buffer, 0, buffer.Length);
     stream.Finish();
     stream.Close();
     return true;
 }
开发者ID:NoobSkie,项目名称:taobao-shop-helper,代码行数:44,代码来源:File.cs

示例15: ZipFileMain

        public void ZipFileMain(string[] args)
        {
            string[] filenames = Directory.GetFiles(args[0]);

            Crc32 crc = new Crc32();
            ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));

            s.SetLevel(6); // 0 - store only to 9 - means best compression

            foreach (string file in filenames)
            {
                //打开压缩文件
                FileStream fs = File.OpenRead(file);

                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                ZipEntry entry = new ZipEntry(file);

                entry.DateTime = DateTime.Now;

                // set Size and the crc, because the information
                // about the size and crc should be stored in the header
                // if it is not set it is automatically written in the footer.
                // (in this case size == crc == -1 in the header)
                // Some ZIP programs have problems with zip files that don't store
                // the size and crc in the header.
                entry.Size = fs.Length;
                fs.Close();

                crc.Reset();
                crc.Update(buffer);

                entry.Crc = crc.Value;

                s.PutNextEntry(entry);

                s.Write(buffer, 0, buffer.Length);

            }

            s.Finish();
            s.Close();
        }
开发者ID:BlueSky007,项目名称:Demo55,代码行数:43,代码来源:ZipFile.cs


注:本文中的ICSharpCode.SharpZipLib.Checksums.Crc32.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。