11using System ;
22using System . IO ;
3+ using System . IO . Compression ;
34using System . Collections . Generic ;
45using System . Net ;
56using System . Text ;
67using System . Threading ;
78using System . Threading . Tasks ;
8- using NumSharp ;
9- using SharpCompress ;
10- using SharpCompress . Common ;
11- using SharpCompress . Readers ;
129
1310namespace 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