本文整理汇总了C#中ICSharpCode.SharpZipLib.Checksums.Crc32.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# Crc32.Reset方法的具体用法?C# Crc32.Reset怎么用?C# Crc32.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Checksums.Crc32
的用法示例。
在下文中一共展示了Crc32.Reset方法的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;
}
}
示例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();
}
示例3: 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);
}
}
}
示例4: 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();
}
}
示例5: 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);
}
}
}
示例6: 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);
}
}
}
示例7: 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();
}
}
示例8: 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();
}
示例9: 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();
}
示例10: 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;
}
}
示例11: AddFile
/// <summary>
/// 在压缩文件中创建一个新的空文件
/// </summary>
/// <param name="fileName"></param>
/// <param name="fileSize"></param>
public void AddFile(string fileName, long fileSize)
{
crc = new Crc32();
crc.Reset();
entry = new ZipEntry(fileName);
entry.DateTime = DateTime.Now;
entry.Size = fileSize;
zipStream.PutNextEntry(entry);
}
示例12: 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;
}
}
示例13: 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();
}
示例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;
}
示例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();
}