Skip to content

Commit 103ffc7

Browse files
committed
Enable bz2 and gzip on all platforms
1 parent f9b4e26 commit 103ffc7

File tree

2 files changed

+11
-40
lines changed

2 files changed

+11
-40
lines changed

BinaryObjectScanner/FileType/BZip2.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using System;
22
using System.IO;
33
using BinaryObjectScanner.Interfaces;
4-
#if NET462_OR_GREATER || NETCOREAPP
5-
using SharpCompress.Compressors;
6-
using SharpCompress.Compressors.BZip2;
7-
#endif
4+
using SabreTools.Compression.BZip2;
85

96
namespace BinaryObjectScanner.FileType
107
{
@@ -29,11 +26,10 @@ 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
{
3531
// Try opening the stream
36-
using var bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true);
32+
using var bz2File = new BZip2InputStream(stream, true);
3733

3834
// Create the output file path
3935
Directory.CreateDirectory(outDir);
@@ -50,9 +46,6 @@ public bool Extract(Stream? stream, string file, string outDir, bool includeDebu
5046
if (includeDebug) Console.WriteLine(ex);
5147
return false;
5248
}
53-
#else
54-
return false;
55-
#endif
5649
}
5750
}
5851
}
Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using System;
22
using System.IO;
33
using 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

96
namespace 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

Comments
 (0)