CloudAppendBlob with seek ability

434 views Asked by At

I have the following scenario.

  • An azure function with timer trigger in consumption plan (that means 1.5GB of Ram)
  • when the timer gets hit a couple of files will be zipped and then uploaded to azure blob as CloudAppendBlob directly by using stream so no data should be written locally or in memory because of the available resources.
  • in some cases, the previously created blob should be opened again as a stream to insert other files

Current Problem It seems that CloudAppendBlob doesn't support writing stream with seek ability.

Example Code:

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse("connection string");
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference("container name");

        var appendBlockBlob = container.GetAppendBlobReference("blob to write to");

        using (CloudBlobStream blobStream = await appendBlockBlob.OpenWriteAsync(false))
        // **here an exception will be thrown because the AppendBlockBlob doensn't support seek that is needed by ZipArchive in update mode**
        using (ZipArchive archive = new ZipArchive(blobStream, ZipArchiveMode.Update, true))
        {
            ZipArchiveEntry entry = archive.CreateEntry("file entry", CompressionLevel.Optimal);
            using (Stream stream = entry.Open())
            using (var file = File.OpenRead("file to be written to blob"))
            {
                await file.CopyToAsync(stream);
            }
        }

Why I need this:

because my code run in azure function that could be terminated for whatever reason like a timeout. so the previously done will not get lost and on next trigger it will continue rather than starting from Beginning

0

There are 0 answers