需要WebService传输文件,需求1断点续传2加密3压缩
不要求多线程,当然文件大小会限制在10M内,文件校验也是必须的。
不知道能否开发成控件??
如果有相关资料的也可贴到此。最好是原理要点解说,源码或者部分实例段。
不要求完整,部分也可。
------解决方案--------------------
/// <summary>
/// 压缩
/// </summary>
/// <param name="zipFilePath"></param>
/// <param name="sourcefilePath"></param>
/// <returns></returns>
public int Zip(string zipFilePath, string sourcefilePath)
{
ZipOutputStream zipStream = null;
FileStream streamWriter = null;
try
{
Crc32 crc32 = new Crc32();
zipStream = new ZipOutputStream(File.Create(zipFilePath));
zipStream.SetLevel(7);
//Specify Password
//if (password != null && password.Trim().Length > 0)
//{
// zipStream.Password = password;
//}
//Check Whether the file exists
if (!File.Exists(sourcefilePath))
{
throw new FileNotFoundException(sourcefilePath);
}
//Read the file to stream
streamWriter = File.OpenRead(sourcefilePath);
byte[] buffer = new byte[streamWriter.Length];
streamWriter.Read(buffer, 0, buffer.Length);
streamWriter.Close();
//Specify ZipEntry
crc32.Reset();
crc32.Update(buffer);
ZipEntry zipEntry = new ZipEntry(Path.Combine("错误报告", Path.GetFileName(sourcefilePath)));
zipEntry.DateTime = DateTime.Now;
zipEntry.Size = buffer.Length;
zipEntry.Crc = crc32.Value;
//Put file info into zip stream
zipStream.PutNextEntry(zipEntry);
//Put file data into zip stream
zipStream.Write(buffer, 0, buffer.Length);
}
catch
{
throw;
}
finally
{
//Clear Resource
if (streamWriter != null)
{
streamWriter.Close();
}
if (zipStream != null)
{
zipStream.Finish();
zipStream.Close();
}
}
return 0;
}
/// <summary>
/// 解压缩
/// </summary>
/// <param name="aimFolder"></param>
/// <param name="zipFilePath"></param>
/// <returns></returns>
public int Unzip(string aimFolder, string zipFilePath)
{
ZipInputStream zipStream = null;
ZipEntry zipEntry = null;
FileStream streamWriter = null;
int count = 0;
try
{
zipStream = new ZipInputStream(File.OpenRead(zipFilePath));
//zipStream.Password = password;
while ((zipEntry = zipStream.GetNextEntry()) != null)
{
string zipFileDirectory = Path.GetDirectoryName(zipEntry.Name);
string destFileDirectory = Path.Combine(aimFolder, zipFileDirectory);
if (!Directory.Exists(destFileDirectory))
{
Directory.CreateDirectory(destFileDirectory);
}
string fileName = Path.GetFileName(zipEntry.Name);