From ca2778b65878bc50b4569e4f31bcd02991c7552d Mon Sep 17 00:00:00 2001
From: Strachu
Date: Mon, 15 Dec 2014 20:57:54 +0100
Subject: [PATCH] Changed the order of detecting whether the archive is in .rar
format.
Its very slow with big archives and shouldn't be done when we got archive in format which can be detected fast.
---
SharpCompress/Archive/ArchiveFactory.cs | 28 ++++++++++++-------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/SharpCompress/Archive/ArchiveFactory.cs b/SharpCompress/Archive/ArchiveFactory.cs
index b778b453..d67cb16b 100644
--- a/SharpCompress/Archive/ArchiveFactory.cs
+++ b/SharpCompress/Archive/ArchiveFactory.cs
@@ -31,12 +31,6 @@ namespace SharpCompress.Archive
return ZipArchive.Open(stream, options, null);
}
stream.Seek(0, SeekOrigin.Begin);
- if (RarArchive.IsRarFile(stream, Options.LookForHeader | Options.KeepStreamsOpen))
- {
- stream.Seek(0, SeekOrigin.Begin);
- return RarArchive.Open(stream, options);
- }
- stream.Seek(0, SeekOrigin.Begin);
if (TarArchive.IsTarFile(stream))
{
stream.Seek(0, SeekOrigin.Begin);
@@ -54,7 +48,13 @@ namespace SharpCompress.Archive
stream.Seek(0, SeekOrigin.Begin);
return GZipArchive.Open(stream, options);
}
- throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
+ stream.Seek(0, SeekOrigin.Begin);
+ if(RarArchive.IsRarFile(stream, Options.LookForHeader | Options.KeepStreamsOpen))
+ {
+ stream.Seek(0, SeekOrigin.Begin);
+ return RarArchive.Open(stream, options);
+ }
+ throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
}
public static IArchive Create(ArchiveType type)
@@ -122,12 +122,6 @@ namespace SharpCompress.Archive
return ZipArchive.Open(fileInfo, options, null);
}
stream.Seek(0, SeekOrigin.Begin);
- if (RarArchive.IsRarFile(stream, Options.LookForHeader | Options.KeepStreamsOpen))
- {
- stream.Dispose();
- return RarArchive.Open(fileInfo, options);
- }
- stream.Seek(0, SeekOrigin.Begin);
if (TarArchive.IsTarFile(stream))
{
stream.Dispose();
@@ -145,7 +139,13 @@ namespace SharpCompress.Archive
stream.Dispose();
return GZipArchive.Open(fileInfo, options);
}
- throw new InvalidOperationException("Cannot determine compressed stream type.");
+ stream.Seek(0, SeekOrigin.Begin);
+ if(RarArchive.IsRarFile(stream, Options.LookForHeader | Options.KeepStreamsOpen))
+ {
+ stream.Dispose();
+ return RarArchive.Open(fileInfo, options);
+ }
+ throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
}
}