-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #671 from vpenades/master
Introduced IArchiveFactory
- Loading branch information
Showing
7 changed files
with
419 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using SharpCompress.Readers; | ||
|
||
namespace SharpCompress.Archives.GZip | ||
{ | ||
public class GZipArchiveFactory : IArchiveFactory | ||
{ | ||
/// <inheritdoc/> | ||
public string Name => "GZip"; | ||
|
||
/// <inheritdoc/> | ||
public IEnumerable<string> GetSupportedExtensions() | ||
{ | ||
yield return "gz"; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool IsArchive(Stream stream, string? password = null) | ||
{ | ||
return GZipArchive.IsGZipFile(stream); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IArchive Open(Stream stream, ReaderOptions? readerOptions = null) | ||
{ | ||
return GZipArchive.Open(stream, readerOptions); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IArchive Open(FileInfo fileInfo, ReaderOptions? readerOptions = null) | ||
{ | ||
return GZipArchive.Open(fileInfo, readerOptions); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IArchive Open(IEnumerable<Stream> streams, ReaderOptions? readerOptions = null) | ||
{ | ||
return GZipArchive.Open(streams, readerOptions); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IArchive Open(IEnumerable<FileInfo> fileInfos, ReaderOptions? readerOptions = null) | ||
{ | ||
return GZipArchive.Open(fileInfos, readerOptions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
using SharpCompress.Common; | ||
using SharpCompress.Readers; | ||
|
||
namespace SharpCompress.Archives | ||
{ | ||
/// <summary> | ||
/// Represents a factory used to identify and open archives. | ||
/// </summary> | ||
/// <remarks> | ||
/// Currently implemented by:<br/> | ||
/// <list type="table"> | ||
/// <item><see cref="Tar.TarArchiveFactory"/></item> | ||
/// <item><see cref="Rar.RarArchiveFactory"/></item> | ||
/// <item><see cref="Zip.ZipArchiveFactory"/></item> | ||
/// <item><see cref="GZip.GZipArchiveFactory"/></item> | ||
/// <item><see cref="SevenZip.SevenZipArchiveFactory"/></item> | ||
/// </list> | ||
/// </remarks> | ||
public interface IArchiveFactory | ||
{ | ||
/// <summary> | ||
/// Gets the archive Type name | ||
/// </summary> | ||
string Name { get; } | ||
|
||
/// <summary> | ||
/// returns the extensions typically used by this archive type. | ||
/// </summary> | ||
/// <returns></returns> | ||
IEnumerable<string> GetSupportedExtensions(); | ||
|
||
/// <summary> | ||
/// Returns true if the stream represents an archive of the format defined by this type. | ||
/// </summary> | ||
/// <param name="stream"></param> | ||
/// /// <param name="password">optional password</param> | ||
bool IsArchive(Stream stream, string? password = null); | ||
|
||
/// <summary> | ||
/// Opens an Archive for random access. | ||
/// </summary> | ||
/// <param name="stream">An open, readable and seekable stream.</param> | ||
/// <param name="readerOptions">reading options.</param> | ||
IArchive Open(Stream stream, ReaderOptions? readerOptions = null); | ||
|
||
/// <summary> | ||
/// Constructor with a FileInfo object to an existing file. | ||
/// </summary> | ||
/// <param name="fileInfo">the file to open.</param> | ||
/// <param name="readerOptions">reading options.</param> | ||
IArchive Open(System.IO.FileInfo fileInfo, ReaderOptions? readerOptions = null); | ||
|
||
/// <summary> | ||
/// Constructor with IEnumerable FileInfo objects, multi and split support. | ||
/// </summary> | ||
/// <param name="streams"></param> | ||
/// <param name="readerOptions">reading options.</param> | ||
IArchive Open(IEnumerable<Stream> streams, ReaderOptions? readerOptions = null); | ||
|
||
/// <summary> | ||
/// Constructor with IEnumerable Stream objects, multi and split support. | ||
/// </summary> | ||
/// <param name="fileInfos"></param> | ||
/// <param name="readerOptions">reading options.</param> | ||
IArchive Open(IEnumerable<System.IO.FileInfo> fileInfos, ReaderOptions? readerOptions = null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using SharpCompress.Readers; | ||
|
||
namespace SharpCompress.Archives.Rar | ||
{ | ||
public class RarArchiveFactory : IArchiveFactory | ||
{ | ||
/// <inheritdoc/> | ||
public string Name => "Rar"; | ||
|
||
/// <inheritdoc/> | ||
public IEnumerable<string> GetSupportedExtensions() | ||
{ | ||
yield return "rar"; | ||
yield return "cbr"; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool IsArchive(Stream stream, string? password = null) | ||
{ | ||
return RarArchive.IsRarFile(stream); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IArchive Open(Stream stream, ReaderOptions? readerOptions = null) | ||
{ | ||
return RarArchive.Open(stream, readerOptions); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IArchive Open(FileInfo fileInfo, ReaderOptions? readerOptions = null) | ||
{ | ||
return RarArchive.Open(fileInfo, readerOptions); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IArchive Open(IEnumerable<Stream> streams, ReaderOptions? readerOptions = null) | ||
{ | ||
return RarArchive.Open(streams, readerOptions); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IArchive Open(IEnumerable<FileInfo> fileInfos, ReaderOptions? readerOptions = null) | ||
{ | ||
return RarArchive.Open(fileInfos, readerOptions); | ||
} | ||
} | ||
} |
Oops, something went wrong.