mirror of https://github.com/abpframework/abp.git
6 changed files with 70 additions and 95 deletions
@ -1,24 +0,0 @@ |
|||
using System; |
|||
using Ionic.Zip; |
|||
|
|||
namespace Volo.Abp.Cli.ProjectBuilding.Files |
|||
{ |
|||
public static class FileEntryListExtensions |
|||
{ |
|||
public static void CopyToZipFile(this FileEntryList fileEntryList, ZipFile zipFile) |
|||
{ |
|||
foreach (var entry in fileEntryList) |
|||
{ |
|||
try |
|||
{ |
|||
zipFile.AddEntry(entry.Name, entry.Bytes); |
|||
} |
|||
catch (Exception e) |
|||
{ |
|||
Console.WriteLine(e); |
|||
throw; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,57 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using Ionic.Zip; |
|||
using Volo.Abp.Cli.ProjectBuilding.Files; |
|||
|
|||
namespace Volo.Abp.Cli.ProjectBuilding.Zipping |
|||
{ |
|||
public static class ZipFileExtensions |
|||
{ |
|||
public static byte[] GetBytes(this ZipFile zipFile) |
|||
{ |
|||
using (var ms = new MemoryStream()) |
|||
{ |
|||
zipFile.Save(ms); |
|||
return ms.ToArray(); |
|||
} |
|||
} |
|||
|
|||
public static FileEntryList ToFileEntryList(this ZipFile zipFile, string rootFolder = null) |
|||
{ |
|||
var zipEntries = zipFile.Entries; |
|||
|
|||
if (rootFolder != null) |
|||
{ |
|||
zipEntries = zipEntries.Where(entry => entry.FileName.StartsWith(rootFolder)).ToList(); |
|||
} |
|||
|
|||
var fileEntries = new List<FileEntry>(); |
|||
|
|||
foreach (var zipEntry in zipEntries) |
|||
{ |
|||
using (var entryStream = zipEntry.OpenReader()) |
|||
{ |
|||
var fileName = zipEntry.FileName; |
|||
|
|||
if (rootFolder != null) |
|||
{ |
|||
fileName = fileName.RemovePreFix(rootFolder); |
|||
} |
|||
|
|||
if (fileName.IsNullOrEmpty()) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
fileName = fileName.EnsureStartsWith('/'); |
|||
|
|||
fileEntries.Add(new FileEntry(fileName, entryStream.GetAllBytes(), zipEntry.IsDirectory)); |
|||
} |
|||
} |
|||
|
|||
return new FileEntryList(fileEntries); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue