diff --git a/src/TensorFlowHub/TensorFlowHub.csproj b/src/TensorFlowHub/TensorFlowHub.csproj index ddf8ca25..45e86713 100644 --- a/src/TensorFlowHub/TensorFlowHub.csproj +++ b/src/TensorFlowHub/TensorFlowHub.csproj @@ -9,6 +9,5 @@ - diff --git a/src/TensorFlowHub/Utils.cs b/src/TensorFlowHub/Utils.cs index 9f71c61d..92828f0d 100644 --- a/src/TensorFlowHub/Utils.cs +++ b/src/TensorFlowHub/Utils.cs @@ -1,14 +1,11 @@ using System; using System.IO; +using System.IO.Compression; using System.Collections.Generic; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; -using NumSharp; -using SharpCompress; -using SharpCompress.Common; -using SharpCompress.Readers; namespace Tensorflow.Hub { @@ -37,7 +34,7 @@ namespace Tensorflow.Hub } } - public static void Unzip(this IModelLoader modelLoader, string zipFile, string saveTo) + public static async Task UnzipAsync(this IModelLoader modelLoader, string zipFile, string saveTo) where TDataSet : IDataSet { if (!Path.IsPathRooted(saveTo)) @@ -46,27 +43,22 @@ namespace Tensorflow.Hub if (!Directory.Exists(saveTo)) Directory.CreateDirectory(saveTo); - using (var stream = File.OpenRead(zipFile)) - using (var reader = ReaderFactory.Open(stream)) + var destFilePath = Path.Combine(saveTo, Path.GetFileNameWithoutExtension(zipFile)); + + if (File.Exists(destFilePath)) + File.Delete(destFilePath); + + using (GZipStream unzipStream = new GZipStream(File.OpenRead(zipFile), CompressionMode.Decompress)) { - while (reader.MoveToNextEntry()) + using (var destStream = File.Create(destFilePath)) { - if (!reader.Entry.IsDirectory) - { - reader.WriteEntryToDirectory(saveTo, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); - } + await unzipStream.CopyToAsync(destStream); + await destStream.FlushAsync(); + destStream.Close(); } - } - } - public static async Task UnzipAsync(this IModelLoader modelLoader, string zipFile, string saveTo) - where TDataSet : IDataSet - { - await Task.Run(() => modelLoader.Unzip(zipFile, saveTo)); + unzipStream.Close(); + } } public static async Task ShowProgressInConsole(this Task task)