Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IsRarFile() StreamingMode #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions SharpCompress/Archive/ArchiveFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SharpCompress.Archive.Tar;
using SharpCompress.Archive.Zip;
using SharpCompress.Common;
using SharpCompress.IO;

namespace SharpCompress.Archive
{
Expand Down Expand Up @@ -43,7 +44,7 @@ public static IArchive Open(Stream stream, Options options = Options.KeepStreams
return GZipArchive.Open(stream, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (RarArchive.IsRarFile(stream, options))
if (RarArchive.IsRarFile(stream, StreamingMode.Seekable, options))
{
stream.Seek(0, SeekOrigin.Begin);
return RarArchive.Open(stream, options);
Expand Down Expand Up @@ -138,7 +139,7 @@ public static IArchive Open(FileInfo fileInfo, Options options)
return GZipArchive.Open(fileInfo, options);
}
stream.Seek(0, SeekOrigin.Begin);
if (RarArchive.IsRarFile(stream, options))
if (RarArchive.IsRarFile(stream, StreamingMode.Seekable, options))
{
stream.Dispose();
return RarArchive.Open(fileInfo, options);
Expand Down
7 changes: 6 additions & 1 deletion SharpCompress/Archive/Rar/RarArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,15 @@ public static bool IsRarFile(Stream stream)
}

public static bool IsRarFile(Stream stream, Options options)
{
return IsRarFile(stream, StreamingMode.Seekable, options);
}

public static bool IsRarFile(Stream stream, StreamingMode streamingMode, Options options)
{
try
{
var headerFactory = new RarHeaderFactory(StreamingMode.Seekable, options);
var headerFactory = new RarHeaderFactory(streamingMode, options);
var markHeader = headerFactory.ReadHeaders(stream).FirstOrDefault() as MarkHeader;
return markHeader != null && markHeader.IsValid();
}
Expand Down
2 changes: 1 addition & 1 deletion SharpCompress/IO/StreamingMode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SharpCompress.IO
{
internal enum StreamingMode
public enum StreamingMode
{
Streaming,
Seekable,
Expand Down
2 changes: 1 addition & 1 deletion SharpCompress/Reader/ReaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static IReader Open(Stream stream, Options options = Options.KeepStreamsO
}

rewindableStream.Rewind(false);
if (RarArchive.IsRarFile(rewindableStream, options))
if (RarArchive.IsRarFile(rewindableStream, StreamingMode.Streaming, options))
{
rewindableStream.Rewind(true);
return RarReader.Open(rewindableStream, options);
Expand Down