Example #1
0
 /// <summary>
 /// Compress list of file entity objects into array of byte.
 /// </summary>
 /// <param name="files">list of files to compress.</param>
 /// <returns></returns>
 public static byte[] Compress(this ConcurrentBag <FileEntity> files)
 {
     if (files.Any())
     {
         var ms = new MemoryStream();
         using (var archive = new ZipArchive(ms, ZipArchiveMode.Create, leaveOpen: true))
         {
             foreach (var file in files)
             {
                 var entry = archive.Add(file);
             }
         }
         ms.Position = 0; //reset memory stream position.
         return(ms.ReadBytes());
     }
     return(null);
 }