Skip to content

Commit ee9aef8

Browse files
committed
fixed a bug about unzip
1 parent d228b6f commit ee9aef8

2 files changed

Lines changed: 14 additions & 23 deletions

File tree

‎src/TensorFlowHub/TensorFlowHub.csproj‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
</ItemGroup>
1010
<ItemGroup>
1111
<PackageReference Include="NumSharp" Version="0.10.5" />
12-
<PackageReference Include="sharpcompress" Version="0.23.0" />
1312
</ItemGroup>
1413
</Project>

‎src/TensorFlowHub/Utils.cs‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
22
using System.IO;
3+
using System.IO.Compression;
34
using System.Collections.Generic;
45
using System.Net;
56
using System.Text;
67
using System.Threading;
78
using System.Threading.Tasks;
8-
using NumSharp;
9-
using SharpCompress;
10-
using SharpCompress.Common;
11-
using SharpCompress.Readers;
129

1310
namespace Tensorflow.Hub
1411
{
@@ -37,7 +34,7 @@ public static async Task DownloadAsync<TDataSet>(this IModelLoader<TDataSet> mod
3734
}
3835
}
3936

40-
public static void Unzip<TDataSet>(this IModelLoader<TDataSet> modelLoader, string zipFile, string saveTo)
37+
public static async Task UnzipAsync<TDataSet>(this IModelLoader<TDataSet> modelLoader, string zipFile, string saveTo)
4138
where TDataSet : IDataSet
4239
{
4340
if (!Path.IsPathRooted(saveTo))
@@ -46,27 +43,22 @@ public static void Unzip<TDataSet>(this IModelLoader<TDataSet> modelLoader, stri
4643
if (!Directory.Exists(saveTo))
4744
Directory.CreateDirectory(saveTo);
4845

49-
using (var stream = File.OpenRead(zipFile))
50-
using (var reader = ReaderFactory.Open(stream))
46+
var destFilePath = Path.Combine(saveTo, Path.GetFileNameWithoutExtension(zipFile));
47+
48+
if (File.Exists(destFilePath))
49+
File.Delete(destFilePath);
50+
51+
using (GZipStream unzipStream = new GZipStream(File.OpenRead(zipFile), CompressionMode.Decompress))
5152
{
52-
while (reader.MoveToNextEntry())
53+
using (var destStream = File.Create(destFilePath))
5354
{
54-
if (!reader.Entry.IsDirectory)
55-
{
56-
reader.WriteEntryToDirectory(saveTo, new ExtractionOptions()
57-
{
58-
ExtractFullPath = true,
59-
Overwrite = true
60-
});
61-
}
55+
await unzipStream.CopyToAsync(destStream);
56+
await destStream.FlushAsync();
57+
destStream.Close();
6258
}
63-
}
64-
}
6559

66-
public static async Task UnzipAsync<TDataSet>(this IModelLoader<TDataSet> modelLoader, string zipFile, string saveTo)
67-
where TDataSet : IDataSet
68-
{
69-
await Task.Run(() => modelLoader.Unzip(zipFile, saveTo));
60+
unzipStream.Close();
61+
}
7062
}
7163

7264
public static async Task ShowProgressInConsole(this Task task)

0 commit comments

Comments
 (0)