0

I'm creating an Azure function that will unzip a zip file full of .csv files, parse the contents, and save data to a database. I'm stuck on the very first step: unzip a zip file.

After reading lots of other threads (including Azure downloadtostreamasync method hangs) this is what I have:

 public async static Task<MemoryStream> GetMemoryStreamAsync(CloudFile inBoundfile)
 {
    MemoryStream memstream = new MemoryStream();
    await inBoundfile.DownloadToStreamAsync(memstream).ConfigureAwait(false);
    return memstream;
 }

The zip file I'm testing with is 515,069KB. When that method is called, it seems to just hang, but eventually throws an Out of Memory exception. I've also tried doing it non-async (which throws the same error) and I've tried it w/o the .ConfigureAwait(false), and in that case, it throws an error with something like directory corrupt (or somethin'.. I forget what exactly).

Oh, I also found a thread that said to put the Azure App at 64bit, which I did.

There MUST be a solution, but I'm not finding it!!

Casey Crookston
  • 13,016
  • 24
  • 107
  • 193
  • 2
    Use a "streaming" unzipper that doesn't require loading the entire shebang into memory at once. – Robert Harvey Mar 26 '19 at 21:45
  • Or use a `FileStream` instead. – Robert Harvey Mar 26 '19 at 21:47
  • @RobertHarvey... ok... that sounds promising. I also have to confess I have no idea how to do that. It's taken me all day to cobble this much together from piecing together all kinds of tidbits from lots of sources! I wish I could find a tutorial on this!! – Casey Crookston Mar 26 '19 at 21:48
  • Will a FileStream work in an Azure Function App? – Casey Crookston Mar 26 '19 at 21:51
  • Good question. Related: https://stackoverflow.com/questions/12715945. Note that, if you're reading sequentially (which you should be), a FileStream and a MemoryStream should be morally equivalent, except that the FileStream won't chew up all of your memory. – Robert Harvey Mar 26 '19 at 21:51
  • https://github.com/haf/DotNetZip.Semverd – Robert Harvey Mar 26 '19 at 21:58
  • okay, so... Given a CloudFile, how do I convert it to a FileStream and not a Memory Stream? Creating a new filestream requires a path to a file... that's why i was wondering if it could be used with a file stored in Azure Stortage. (I'm googling this now, but not finding much) – Casey Crookston Mar 27 '19 at 00:15
  • i'm looking at the DotNetZip giyhub you linked to... Not seeing anything there about Azure Storage. It looks like it's all meant for local file system stuff. Am I wrong? – Casey Crookston Mar 27 '19 at 00:46

0 Answers0