title: Generating a zipOutputstream from a folder having other .zip files in it
body: <p>I am trying to convert an entire azure blob storage folder and its contents to a zip file .Inside this folder ,I have different types of files eg, .txt,.mp3,.zip files .But once the folder is converted to zip file I noticed that all the .zip file types got corrupted,.<strong>How can I prevent my zip files from corrupted</strong>. I am using  <a href="http://dotnetzip.codeplex.com/" rel="nofollow noreferrer">Ionic.Zip library</a> to generate zip files</p>
  
  <p><strong>Here is the code I am using</strong> .<em>Here I am able to generate and download the zip file successfully with all other filetypes</em> <em>except the inner zip files</em>.</p>
  
  <pre><code>var allFiles = directory.ListBlobs(new BlobRequestOptions { UseFlatBlobListing = true }).Where(x =&gt; x.GetType() == typeof(CloudBlockBlob)).Cast&lt;CloudBlob&gt;();
  
  string xyzblob = directory.Uri.ToString().TrimEnd('/');
  var dBlob = blobClient.GetBlobReference(xyzblob);
  byte[] fileBytes = null;
  fileBytes = dBlob.DownloadByteArray();
  foreach (var file in allFiles)
  {
      using (var fileStream = new MemoryStream(fileBytes))
      {
          var entryName = file.Uri.ToString().Replace(directory.Uri.ToString(), "");
           zipOutputStream.PutNextEntry(entryName);
           fileStream.Seek(0, SeekOrigin.Begin);
           int count = fileStream.Read(fileBytes, 0, fileBytes.Length);
           while (count &gt; 0)
           {
               zipOutputStream.Write(fileBytes, 0, count);
  
              count = fileStream.Read(fileBytes, 0, fileBytes.Length);
              if (!Response.IsClientConnected)
              {
                  break;
              }
              Response.Flush();
          }
          fileStream.Close();
       }
  }
  zipOutputStream.Close(); 
  </code></pre>
  
  <p>More details</p>
  
  <p>I am downloading a folder ,."myFolder" and its contents from azure blob as a zip file eg, myfolders.zip.</p>
  
  <p>Here is how the file structure inside "myFolder" /azure blob</p>
  
  <p>MyFolder/mymusic/ test.mp3</p>
  
  <p>MyFolder/mytext/ newtext.txt</p>
  
  <p>MyFolder/MyZipfiles/ myzip.zip</p>
  
  <p>My code I posted above will generate a zip all the contents of the folder to create "MyFolder.zip" and will download automatically .Now if you unzip "MyFolder.zip" file , due to some reason , the myzip.zip is getting corrupted.If I try to open myzip.zip file ,its showing a message "windows cannot open the folder ,the compressed zipped folder "myzip.zip" is invalid"</p>
  
  <p>Please help me find a solution so that the .zip files wont get corrupted </p>
  
  <p>I tried to download to stream ,but same results.,The inner zip files are getting corrupted.all other file types are in good shape. 
                    zipOutputStream.PutNextEntry(entryName);
                      destBlob.DownloadToStream(zipOutputStream);</p>