Try reading files if streams fail

This commit is contained in:
Matt Nadareski
2024-12-03 06:00:03 -05:00
parent 0d213274b5
commit 03a2dff668
4 changed files with 24 additions and 4 deletions

View File

@@ -42,7 +42,12 @@ namespace BinaryObjectScanner.FileType
try
{
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
using var zipFile = ZipArchive.Open(stream, readerOptions);
var zipFile = ZipArchive.Open(stream, readerOptions);
// Try to read the file path if no entries are found
if (zipFile.Entries.Count == 0 && !string.IsNullOrEmpty(file) && File.Exists(file))
zipFile = ZipArchive.Open(file, readerOptions);
foreach (var entry in zipFile.Entries)
{
try

View File

@@ -42,7 +42,12 @@ namespace BinaryObjectScanner.FileType
try
{
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
using RarArchive rarFile = RarArchive.Open(stream, readerOptions);
RarArchive rarFile = RarArchive.Open(stream, readerOptions);
// Try to read the file path if no entries are found
if (rarFile.Entries.Count == 0 && !string.IsNullOrEmpty(file) && File.Exists(file))
rarFile = RarArchive.Open(file, readerOptions);
if (!rarFile.IsComplete)
return false;

View File

@@ -42,7 +42,12 @@ namespace BinaryObjectScanner.FileType
try
{
var readerOptions = new ReaderOptions() { LookForHeader = lookForHeader };
using var sevenZip = SevenZipArchive.Open(stream, readerOptions);
var sevenZip = SevenZipArchive.Open(stream, readerOptions);
// Try to read the file path if no entries are found
if (sevenZip.Entries.Count == 0 && !string.IsNullOrEmpty(file) && File.Exists(file))
sevenZip = SevenZipArchive.Open(file, readerOptions);
foreach (var entry in sevenZip.Entries)
{
try

View File

@@ -32,7 +32,12 @@ namespace BinaryObjectScanner.FileType
#if NET462_OR_GREATER || NETCOREAPP
try
{
using var tarFile = TarArchive.Open(stream);
var tarFile = TarArchive.Open(stream);
// Try to read the file path if no entries are found
if (tarFile.Entries.Count == 0 && !string.IsNullOrEmpty(file) && File.Exists(file))
tarFile = TarArchive.Open(file);
foreach (var entry in tarFile.Entries)
{
try