将零散文件使用ICSharpCode.SharpZipLib压缩打包后一次性下载
来源:互联网 发布:淘宝卖家图片详情模板 编辑:程序博客网 时间:2024/04/25 21:52
public static Stream CreateZip(List<string> listPath, int level = 5){MemoryStream mstream = new MemoryStream();using (ZipOutputStream zipstream = new ZipOutputStream(mstream)){zipstream.SetLevel(level);Crc32 crc = new Crc32();foreach (var path in listPath){FileStream fs = File.Open(path, FileMode.Open);//重置流的位置fs.Position = 0L;byte[] buffer = new byte[fs.Length];fs.Read(buffer, 0, buffer.Length);//ZIP文件条目ZipEntry entry = new ZipEntry(Path.GetFileName(path));entry.DateTime = DateTime.Now;entry.Size = fs.Length;fs.Close();crc.Reset();crc.Update(buffer);//冗余校验码entry.Crc = crc.Value;zipstream.PutNextEntry(entry);zipstream.Write(buffer, 0, buffer.Length);}//ZipOutputStream关闭后不关闭mstreamzipstream.IsStreamOwner = false;}//重置流的位置mstream.Position = 0L;return mstream;}
使用流读取并压缩文件。
zipstream.IsStreamOwner = false;必须设置
在MVC中使用FileStreamResult File(Stream fileStream, string contentType, string fileDownloadName)方法可直接下载。
contentType可使用"application/x-zip-compressed"表示zip文件类型。
0 0
- 将零散文件使用ICSharpCode.SharpZipLib压缩打包后一次性下载
- C#使用ICSharpCode.SharpZipLib压缩后进行web批量下载文件
- 使用ICSharpCode.SharpZipLib对文件进行压缩或解压
- C#使用ICSharpCode.SharpZipLib对文件进行压缩
- C#中ICSharpCode.SharpZipLib 压缩、解压文件
- ICSharpCode.SharpZipLib压缩解压
- 使用ICSharpCode.SharpZipLib进行文件压缩,目前还没实现加密压缩/解压缩。
- 使用ICSharpCode.SharpZipLib.dll解压指定文件
- 多文件打包压缩、下载类--使用第三方控件ICSharpCode
- ICSharpCode.SharpZipLib 使用演示
- ICSharpCode.SharpZipLib 初级使用
- ICSharpCode.SharpZipLib 初级使用
- ICSharpCode.SharpZipLib.Zip 使用
- 通过ICSharpCode.SharpZipLib.dll压缩和解压ZIP文件
- .Net 下利用ICSharpCode.SharpZipLib.dll实现文件压缩、解压缩
- ICSharpCode.SharpZipLib压缩的文件不能解压的原因
- C# ICSharpCode.SharpZipLib 压缩、解压文件 附源码
- 压缩/解压(ICSharpCode.SharpZipLib 类库)
- 不让EditText进入界面后自动获取焦点
- React Component生命周期
- Springmvc + Mybatis + IntelliJ IDEA 环境搭建
- SQL Server 触发器
- HDU1040(Java)
- 将零散文件使用ICSharpCode.SharpZipLib压缩打包后一次性下载
- pycharm快捷键、常用设置、包管理
- 学习日记20160831
- 201503-3 节日
- PyCharm管理解释器及第三方模块、包
- Android开发入门之基本界面组件
- activit-----HelloWorld入门流程初试
- Spring Quartz动态配置时间
- hadoop cdh maven