Dig*_*ift 6 c# zip azure azure-storage-blobs dotnetzip
我将文件存储在blob存储帐户中的一个容器中.我需要在第二个容器中创建一个zip文件,其中包含第一个容器中的文件.
我有一个使用worker角色和DotNetZip工作的解决方案,但因为zip文件最终可能是1GB大小我担心在进程中使用MemoryStream对象等进行所有工作并不是最好的方法.我最关心的是内存使用和释放资源,因为这个过程可能每天发生几次.
下面是一些非常简化的代码,显示了worker角色的基本过程:
using (ZipFile zipFile = new ZipFile())
{
foreach (var uri in uriCollection)
{
var blob = new CloudBlob(uri);
byte[] fileBytes = blob.DownloadByteArray();
using (var fileStream = new MemoryStream(fileBytes))
{
fileStream.Seek(0, SeekOrigin.Begin);
byte[] bytes = CryptoHelp.EncryptAsBytes(fileStream, "password", null);
zipFile.AddEntry("entry name", bytes);
}
}
using (var zipStream = new MemoryStream())
{
zipFile.Save(zipStream);
zipStream.Seek(0, SeekOrigin.Begin);
var blobRef = ContainerDirectory.GetBlobReference("output uri");
blobRef.UploadFromStream(zipStream);
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以提出更好的方法吗?
在撰写此问题时,我不知道 Azure 中提供了 LocalStorage 选项。我能够将文件单独写入此文件并在 LocalStorage 中使用它们,然后将它们写回 blob 存储。
| 归档时间: |
|
| 查看次数: |
3413 次 |
| 最近记录: |