首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

需要WebService传输文件,需求1断点续传2加密3压缩解决办法

2012-01-08 
需要WebService传输文件,需求1断点续传2加密3压缩需要WebService传输文件,需求1断点续传2加密3压缩不要求

需要WebService传输文件,需求1断点续传2加密3压缩
需要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);


if (fileName.Length > 0)
{
string destFilePath = Path.Combine(destFileDirectory, fileName);

streamWriter = File.Create(destFilePath);
int size = 2048;
byte[] data = new byte[2048];
int extractCount = 0;
while (true)
{
size = zipStream.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
extractCount += size;
}

streamWriter.Flush();
streamWriter.Close();
count++;
}
}
}
catch
{
throw;
}
finally
{
if (zipStream != null)
{
zipStream.Close();
}

if (streamWriter != null)
{
streamWriter.Close();
}
}

return count;
}

[解决办法]
Up
changjiangzhibin@gmail.com
[解决办法]
很厉害。1楼。收藏。
[解决办法]
1楼,很好。
LZ请发zzuyongp@163.com 谢谢

热点排行