本文整理汇总了C#中ICSharpCode.SharpZipLib.Checksums.Crc32类的典型用法代码示例。如果您正苦于以下问题:C# Crc32类的具体用法?C# Crc32怎么用?C# Crc32使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Crc32类属于ICSharpCode.SharpZipLib.Checksums命名空间,在下文中一共展示了Crc32类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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
示例2: 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
示例3: 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
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例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: 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
示例10: 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
示例11: 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
示例12: 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);
}
开发者ID:abc52406,项目名称:PbTool,代码行数:14,代码来源:ZipOutputHelper.cs
示例13: File
/// <summary>
/// 将多个文件压缩成一个文件
/// </summary>
/// <param name="source">多个文件,采用全路径,例:e:\tmp\tmp1\DD.cs</param>
/// <param name="descZip">目标ZIP文件路径</param>
/// <param name="password">密码</param>
public void File(string[] source, string descZip, string password = null) {
ZipOutputStream outStream = new ZipOutputStream(System.IO.File.Create(descZip));
if (!password.IsNullEmpty()) outStream.Password = password;
Crc32 crc = new Crc32();
foreach (string info in source) {
File(info, crc, outStream);
}
outStream.Finish();
outStream.Close();
}
开发者ID:pczy,项目名称:Pub.Class,代码行数:16,代码来源:Compress.cs
示例14: ZipOutputStream
public ZipOutputStream(Stream baseOutputStream, int bufferSize) : base(baseOutputStream, new Deflater(-1, true), bufferSize)
{
this.entries = new ArrayList();
this.crc = new Crc32();
this.defaultCompressionLevel = -1;
this.curMethod = CompressionMethod.Deflated;
this.zipComment = new byte[0];
this.crcPatchPos = -1L;
this.sizePatchPos = -1L;
this.useZip64_ = ICSharpCode.SharpZipLib.Zip.UseZip64.Dynamic;
}
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:11,代码来源:ZipOutputStream.cs
示例15: 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
示例16: 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
示例17: 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
示例18: ZipFileMain
/// <summary>
/// 压缩文件
/// </summary>
/// <param name="fileName">要压缩的所有文件(完全路径)</param>
/// <param name="fileName">文件名称</param>
/// <param name="name">压缩后文件路径</param>
/// <param name="Level">压缩级别</param>
public static void ZipFileMain(string[] filenames, string[] fileName, string name, int Level)
{
#region MyRegion
ZipOutputStream s = new ZipOutputStream(File.Create(name));
Crc32 crc = new Crc32();
//压缩级别
s.SetLevel(Level); // 0 - store only to 9 - means best compression
try
{
int m = 0;
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(fileName[m].ToString());//原文件名
//时间
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);
m++;
}
}
catch
{
throw;
}
finally
{
s.Finish();
s.Close();
}
#endregion
}
开发者ID:503945930,项目名称:baoxin,代码行数:49,代码来源:Zip.cs
示例19: WriteFile
/// <summary>
/// Производит компрессию указанного потока. Сжатые данные добавляются в конец
/// выходного потока.
/// </summary>
/// <param name="fileName">Имя файла (записи в ZIP-потоке).</param>
/// <param name="srcStream">Поток данных для сжатия.</param>
public void WriteFile( string fileName, Stream srcStream )
{
byte[] buffer = new byte[srcStream.Length];
srcStream.Read( buffer, 0, buffer.Length );
// контрольная сумма
Crc32 crc = new Crc32();
crc.Reset();
crc.Update( buffer );
// добавить запись о файле в результирующий поток
ZipEntry entry = new ZipEntry( fileName );
entry.DateTime = DateTime.Now;
entry.Size = srcStream.Length;
entry.Crc = crc.Value;
m_zipStream.PutNextEntry( entry );
// сжать и записать буфер данных в результирующий поток
m_zipStream.Write( buffer, 0, buffer.Length );
}
开发者ID:Confirmit,项目名称:Portal,代码行数:26,代码来源:ZipWriter.cs
示例20: _Unir
protected override void _Unir(string fichero, string dirDest)
{
CutterTail tailInicial = CutterTail.LoadFromFile (fichero);
if (tailInicial != null)
{
string destino = dirDest + Path.DirectorySeparatorChar + tailInicial.Original;
long total = tailInicial.FileSize;
long transferidos = 0;
Stream fos = UtilidadesFicheros.CreateWriter (destino);
string ficheroBase = fichero.Substring (0, fichero.Length - 1);
int contador = 1;
CutterTail tail = null;
byte[] buffer = new byte[Consts.BUFFER_LENGTH];
OnProgress (0, total);
Crc32 crc = new Crc32 ();
while ((tail = CutterTail.LoadFromFile (ficheroBase + contador)) != null) {
int leidos = 0;
int parcial = 0;
long fileSize = new FileInfo (ficheroBase + contador).Length;
FileStream fis = File.OpenRead (ficheroBase + contador);
crc.Reset ();
while ((leidos = fis.Read (buffer, 0, Math.Min ((int)fileSize - CutterTail.TAIL_SIZE - parcial, buffer.Length))) > 0)
{
fos.Write (buffer, 0, leidos);
crc.Update (buffer, 0, leidos);
parcial += leidos;
transferidos += leidos;
}
fis.Close ();
if (crc.Value != tail.Crc)
{
throw new Dalle.Formatos.ChecksumVerificationException ("checksum failed on file " + contador, ficheroBase + contador );
}
contador++;
}
fos.Close();
}
}
开发者ID:albfernandez,项目名称:dalle,代码行数:39,代码来源:Cutter.cs
注:本文中的ICSharpCode.SharpZipLib.Checksums.Crc32类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论