62,046
社区成员
发帖
与我相关
我的任务
分享
internal static void DownloadForPressVer2(List<Model.FileEntity> files, string filename)
{
MemoryStream ms = new MemoryStream();
ZipOutputStream zipOutput = new ZipOutputStream(ms);
zipOutput.UseZip64 = UseZip64.Off;
Crc32 oCrc32 = new Crc32();
try
{
foreach (var file in files)
{
if (!File.Exists(HttpContext.Current.Server.MapPath(file.FilePath)))
{
continue;
}
byte[] buffer = null;
string currentFileName = file.FileName;
ZipEntry oZipEntry = new ZipEntry(currentFileName);
oZipEntry.CompressionMethod = CompressionMethod.Deflated;
using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(file.FilePath), FileMode.Open, FileAccess.Read))
{
buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int) fs.Length);
}
oCrc32.Reset();
oCrc32.Update(buffer);
oZipEntry.Crc = oCrc32.Value;
zipOutput.PutNextEntry(oZipEntry);
zipOutput.Write(buffer, 0, buffer.Length);
}
}
catch (Exception)
{
throw;
}
finally
{
zipOutput.Finish();
zipOutput.Close();
}
byte[] bytes = ms.GetBuffer();
ms.Dispose();
DownloadFile(bytes, filename + ".zip");
}