【发布时间】:2015-03-24 20:28:35
【问题描述】:
我正在尝试通过 ZipoutputStream 下载我正在压缩(存档)的一堆文件。
using (var zipStream = new ZipOutputStream(outputMemStream))
{
foreach (var documentIdString in documentUniqueIdentifiers)
{
...
var blockBlob = container.GetBlockBlobReference(documentId.ToString());
var fileMemoryStream = new MemoryStream();
blockBlob.DownloadToStream(fileMemoryStream);
zipStream.SetLevel(3);
fileMemoryStream.Position = 0;
ZipEntry newEntry = new ZipEntry(document.FileName);
newEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(newEntry);
fileMemoryStream.Seek(0, SeekOrigin.Begin);
StreamUtils.Copy(fileMemoryStream, zipStream, new byte[4096]);
zipStream.IsStreamOwner = false; // False stops the Close also Closing the underlying stream.
}
outputMemStream.Seek(0, SeekOrigin.Begin);
return outputMemStream;
}
在我的控制器中,我返回以下代码,该代码应下载我在上一个示例中创建的 Zip 文件。控制器操作在浏览器中下载文件,但存档文件为空。我可以看到从上述方法返回的填充内容长度...
file.Seek(0, SeekOrigin.Begin);
return File(file, "application/octet-stream", "Archive.zip");
有人知道为什么我的控制器返回的文件是空的或损坏的吗?
【问题讨论】:
标签: c# .net memorystream sharpziplib