コード例 #1
0
ファイル: ZipFile.cs プロジェクト: zwyi1985/ASP.NET-MVC-CMS
 private void CollectFile(string root, FileInfo file, ZipFileInfoCollection zipFiles)
 {
     using (FileStream fileStream = file.OpenRead())
     {
         if ((File.GetAttributes(file.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & file.Extension != ".gz")
         {
             using (MemoryStream memoryStream = new MemoryStream())
             {
                 byte[] array = new byte[10240];
                 int    count;
                 while ((count = fileStream.Read(array, 0, array.Length)) > 0)
                 {
                     memoryStream.Write(array, 0, count);
                 }
                 zipFiles.Add(new ZipFileInfo
                 {
                     FileBytes    = memoryStream.ToArray(),
                     RelativePath = root + file.Name
                 });
             }
         }
     }
 }
コード例 #2
0
ファイル: ZipFile.cs プロジェクト: SeriaWei/GZipMultipleFiles
 private void CollectFile(string root, FileInfo file, ZipFileInfoCollection zipFiles)
 {
     using (FileStream originalFileStream = file.OpenRead())
     {
         if ((File.GetAttributes(file.FullName) &
              FileAttributes.Hidden) != FileAttributes.Hidden & file.Extension != ".gz")
         {
             using (MemoryStream ms = new MemoryStream())
             {
                 byte[] buffer = new byte[10240];
                 int    count  = 0;
                 while ((count = originalFileStream.Read(buffer, 0, buffer.Length)) > 0)
                 {
                     ms.Write(buffer, 0, count);
                 }
                 zipFiles.Add(new ZipFileInfo
                 {
                     FileBytes    = ms.ToArray(),
                     RelativePath = string.IsNullOrEmpty(root) ? "\\" + file.Name : file.DirectoryName.Replace(root, "") + "\\" + file.Name
                 });
             }
         }
     }
 }