创建蔚蓝Blob存储内的原位一个zip文件 [英] Creating a zip file in situ within azure blob storage

查看:345
本文介绍了创建蔚蓝Blob存储内的原位一个zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Blob存储账户内的存储在一个容器文件。我需要从第一容器包含文件的第二个容器中创建一个zip文件。

I have files stored in one container within a blob storage account. I need to create a zip file in a second container containing the files from the first container.

我在使用辅助角色和DotNetZip但因为zip文件可能最终在大小为1GB我很担心,做所有的工作流程,使用的MemoryStream 对象等是不​​是这样做的最佳方式。我最大的担忧是,内存使用和释放鉴于此过程中可能发生的,每天数次资源。

I have a solution that works using a worker role and DotNetZip but because the zip file could end up being 1GB in size I am concerned that doing all the work in-process, using MemoryStream objects etc. is not the best way of doing this. My biggest concern is that of memory usage and freeing up resources given that this process could happen several times a day.

下面是一些的非常的精简code显示辅助角色的基本过程:

Below is some very stripped down code showing the basic process in the worker role:

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);
    }

}

一个人能否提供一个更好的方法吗?

Can someone suggest a better approach please?

推荐答案

在编写这个问题的时候,我不知道在Azure中可用的localStorage的选项。我能单独文件写入这和localStorage的范围内与他们的工作,然后将它们写回Blob存储。

At the time of writing this question, I was unaware of the LocalStorage options available in Azure. I was able to write files individually to this and the work with them within the LocalStorage and then write them back to blob storage.

这篇关于创建蔚蓝Blob存储内的原位一个zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆