11using System ;
22using System . IO ;
33using BinaryObjectScanner . Interfaces ;
4- #if NET462_OR_GREATER || NETCOREAPP
5- using SharpCompress . Archives ;
6- using SharpCompress . Archives . GZip ;
7- #endif
4+ using SabreTools . Compression . Deflate ;
85
96namespace BinaryObjectScanner . FileType
107{
@@ -29,34 +26,18 @@ public bool Extract(Stream? stream, string file, string outDir, bool includeDebu
2926 if ( stream == null || ! stream . CanRead )
3027 return false ;
3128
32- #if NET462_OR_GREATER || NETCOREAPP
3329 try
3430 {
35- using var zipFile = GZipArchive . Open ( stream ) ;
36- foreach ( var entry in zipFile . Entries )
37- {
38- try
39- {
40- // If the entry is a directory
41- if ( entry . IsDirectory )
42- continue ;
31+ // Try opening the stream
32+ using var gzipFile = new GZipStream ( stream , CompressionMode . Decompress , true ) ;
4333
44- // If the entry has an invalid key
45- if ( entry . Key == null )
46- continue ;
34+ // Create the output file path
35+ Directory . CreateDirectory ( outDir ) ;
36+ string tempFile = Path . Combine ( outDir , Guid . NewGuid ( ) . ToString ( ) ) ;
4737
48- string tempFile = Path . Combine ( outDir , entry . Key ) ;
49- var directoryName = Path . GetDirectoryName ( tempFile ) ;
50- if ( directoryName != null && ! Directory . Exists ( directoryName ) )
51- Directory . CreateDirectory ( directoryName ) ;
52-
53- entry . WriteToFile ( tempFile ) ;
54- }
55- catch ( Exception ex )
56- {
57- if ( includeDebug ) Console . WriteLine ( ex ) ;
58- }
59- }
38+ // Extract the file
39+ using FileStream fs = File . OpenWrite ( tempFile ) ;
40+ gzipFile . CopyTo ( fs ) ;
6041
6142 return true ;
6243 }
@@ -65,9 +46,6 @@ public bool Extract(Stream? stream, string file, string outDir, bool includeDebu
6546 if ( includeDebug ) Console . WriteLine ( ex ) ;
6647 return false ;
6748 }
68- #else
69- return false ;
70- #endif
7149 }
7250 }
7351}
0 commit comments