作者J002 (阿里山 我来了XD~)
看板C_Sharp
标题Re: [问题] 一次下载多笔资料库的image资料
时间Mon May 23 22:42:48 2016
之前写过从DB捞档案後用7z压缩
然後把压缩後的stream丢到网页给使用者下载
使用的lib叫"SharpZipLib"
缺点就是要把7z的dll档丢进去专案资料夹内
(可能可以用nuget,但是当时没这样处理)
大致上如下:
------------- 懒得帮code上色了0rz ------------
// dllPath就是对应到7z.dll的绝对位置
// 可能会长这个样子:"c:/project/wwwroot/7z.dll"
// 要考虑到如果是在x64的环境下,要用7zx64.dll
var memoryStream = new MemoryStream();
SevenZipBase.SetLibraryPath(dllPath);
var zipCompressor = new SevenZipCompressor
{
ArchiveFormat = OutArchiveFormat.SevenZip,
CompressionMode = CompressionMode.Create,
DirectoryStructure = false
};
var dictForComporess = new Dictionary<string, Stream>();
// dbFiles是已经从db读出来的List<自订类别DbFile>
dbFiles.ForEach(file =>
{
// file.FileContent是byte[]
var stream = new MemoryStream(file.FileContent);
dictForComporess.Add(file.FileName, stream);
});
zipCompressor.CompressStreamDictionary(dictForComporess, memoryStream);
----------- 我是分隔线 ---------
当初有试过用.net内建(还是windows内建的?)的zip lib
但是QA(使用Mac)反应:解开後档名是乱码
所以後来改成用7z打包
以上,给您参考
也请各位前辈先进能给予指点<(_ _)>
※ 编辑: J002 (118.165.31.108), 05/23/2016 22:43:17
※ 编辑: J002 (118.165.31.108), 05/23/2016 22:50:09
1F:推 kisha024: 谢谢 05/30 00:35