diff --git a/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj b/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj index 64b113fba9..267acd2566 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj +++ b/framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj @@ -12,7 +12,7 @@ - + diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs index 7ab05bf02c..55d9e4b1de 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/NewCommand.cs @@ -2,7 +2,8 @@ using System; using System.IO; using System.Text; using System.Threading.Tasks; -using Ionic.Zip; +using ICSharpCode.SharpZipLib.Core; +using ICSharpCode.SharpZipLib.Zip; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Args; @@ -61,9 +62,31 @@ namespace Volo.Abp.Cli.Commands using (var templateFileStream = new MemoryStream(result.ZipContent)) { - using (var templateZipFile = ZipFile.Read(templateFileStream)) + var zipInputStream = new ZipInputStream(templateFileStream); + var zipEntry = zipInputStream.GetNextEntry(); + while (zipEntry != null) { - templateZipFile.ExtractAll(outputFolder, ExtractExistingFileAction.Throw); + var fullZipToPath = Path.Combine(outputFolder, zipEntry.Name); + var directoryName = Path.GetDirectoryName(fullZipToPath); + + if (!string.IsNullOrEmpty(directoryName)) + { + Directory.CreateDirectory(directoryName); + } + + var fileName = Path.GetFileName(fullZipToPath); + if (fileName.Length == 0) + { + zipEntry = zipInputStream.GetNextEntry(); + continue; + } + + var buffer = new byte[4096]; // 4K is optimum + using (var streamWriter = File.Create(fullZipToPath)) + { + StreamUtils.Copy(zipInputStream, streamWriter, buffer); + } + zipEntry = zipInputStream.GetNextEntry(); } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/CreateProjectResultZipStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/CreateProjectResultZipStep.cs index 53e9415617..cc27885771 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/CreateProjectResultZipStep.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/CreateProjectResultZipStep.cs @@ -1,6 +1,6 @@ -using Ionic.Zip; +using System.IO; +using ICSharpCode.SharpZipLib.Zip; using Volo.Abp.Cli.ProjectBuilding.Files; -using Volo.Abp.Cli.ProjectBuilding.Zipping; namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps { @@ -13,10 +13,27 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps private static byte[] CreateZipFileFromEntries(FileEntryList entries) { - using (var resultZipFile = new ZipFile()) + using (var memoryStream = new MemoryStream()) { - entries.CopyToZipFile(resultZipFile); - return resultZipFile.GetBytes(); + var zipOutputStream = new ZipOutputStream(memoryStream); + zipOutputStream.SetLevel(3); //0-9, 9 being the highest level of compression + + foreach (var entry in entries) + { + zipOutputStream.PutNextEntry(new ZipEntry(entry.Name) + { + Size = entry.Bytes.Length + }); + zipOutputStream.Write(entry.Bytes, 0, entry.Bytes.Length); + } + + zipOutputStream.CloseEntry(); + + zipOutputStream.IsStreamOwner = false; + zipOutputStream.Close(); + + memoryStream.Position = 0; + return memoryStream.ToArray(); } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/FileEntryListReadStep.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/FileEntryListReadStep.cs index 3484621df1..d4ba62582d 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/FileEntryListReadStep.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/FileEntryListReadStep.cs @@ -1,7 +1,9 @@ -using System.IO; -using Ionic.Zip; +using System; +using System.Collections.Generic; +using System.IO; +using ICSharpCode.SharpZipLib.Core; +using ICSharpCode.SharpZipLib.Zip; using Volo.Abp.Cli.ProjectBuilding.Files; -using Volo.Abp.Cli.ProjectBuilding.Zipping; namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps { @@ -16,10 +18,24 @@ namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps { using (var memoryStream = new MemoryStream(fileBytes)) { - using (var templateZipFile = ZipFile.Read(memoryStream)) + var fileEntries = new List(); + + var zipInputStream = new ZipInputStream(memoryStream); + var zipEntry = zipInputStream.GetNextEntry(); + while (zipEntry != null) { - return templateZipFile.ToFileEntryList(); + var buffer = new byte[4096]; // 4K is optimum + + using (var fileEntryMemoryStream = new MemoryStream()) + { + StreamUtils.Copy(zipInputStream, fileEntryMemoryStream, buffer); + fileEntries.Add(new FileEntry(zipEntry.Name.EnsureStartsWith('/'), fileEntryMemoryStream.ToArray(), zipEntry.IsDirectory)); + } + + zipEntry = zipInputStream.GetNextEntry(); } + + return new FileEntryList(fileEntries); } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryListExtensions.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryListExtensions.cs deleted file mode 100644 index d8eff66813..0000000000 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Files/FileEntryListExtensions.cs +++ /dev/null @@ -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; - } - } - } - } -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Zipping/ZipFileExtensions.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Zipping/ZipFileExtensions.cs deleted file mode 100644 index 0160c8390e..0000000000 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Zipping/ZipFileExtensions.cs +++ /dev/null @@ -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(); - - 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); - } - } -}