How to append ZipArchive in Azure Functions

Viewed 1034

I'm using Azure Functions(v2) and blob storage. I want to generate a zip from many blob files.

The blob file is large and large in size so as to reach the Threshold memory of Functions.

I use System.IO.Compression.ZipArchive and I referred to How to zip huge files in a blob using stream

using (var blobStream = await archiveBlob.OpenWriteAsync()) using (var resultArchive = new ZipArchive(blobStream, ZipArchiveMode.Create, true)) ....

But next, I reached Threashold 5 minutes. So I try to split the function and gradually add files to Zip, but exception occurred at ZipArchive.

using (var resultArchive = new ZipArchive(blobStream, ZipArchiveMode.Update, true)) --> Microsoft.Azure.WebJobs.FunctionFailedException "Update mode requires a stream with read, write, and seek capabilities."

  • Can BlockBlob be opened with read and write capability?
  • Or have other ideas?

thanks.

1 Answers

I have come to the same problem. Since nobody answered anything that would bring you closer to the solution, I will tell you my experience in mitigating the problem. You have 2 possible solutions

  1. Split the file into multiple zipped archives (optionally zip those already zipped archives into one at the end). You can achieve concurrency here by using Azure Durable Functions.

  2. Move zipping process to Azure WebJob. Unlike Azure Functions, Azure WebJobs do not have that kind of strict time limitation such as Azure Functions, and they are specifically made for this kind of long-running tasks. You can trigger WebJob from Azure Function or from your web api.

Related