/// <summary> /// Constructor with a FileInfo object to an existing file. /// </summary> /// <param name="fileInfo"></param> /// <param name="options"></param> public static IArchive Open(FileInfo fileInfo, Options options) { fileInfo.CheckNotNull("fileInfo"); using (var stream = fileInfo.OpenRead()) { if (ZipArchive.IsZipFile(stream)) { return ZipArchive.Open(fileInfo, options); } stream.Seek(0, SeekOrigin.Begin); if (RarArchive.IsRarFile(stream)) { return RarArchive.Open(fileInfo, options); } throw new InvalidOperationException("Cannot determine compressed stream type."); } }
/// <summary> /// Constructor with a FileInfo object to an existing file. /// </summary> /// <param name="fileInfo"></param> /// <param name="options"></param> public static IArchive Open(FileInfo fileInfo, Options options) { fileInfo.CheckNotNull("fileInfo"); using (var stream = fileInfo.OpenRead()) { if (ZipArchive.IsZipFile(stream, null)) { stream.Dispose(); 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(); return TarArchive.Open(fileInfo, options); } stream.Seek(0, SeekOrigin.Begin); if (SevenZipArchive.IsSevenZipFile(stream)) { stream.Dispose(); return SevenZipArchive.Open(fileInfo, options); } stream.Seek(0, SeekOrigin.Begin); if (GZipArchive.IsGZipFile(stream)) { stream.Dispose(); return GZipArchive.Open(fileInfo, options); } throw new InvalidOperationException("Cannot determine compressed stream type."); } }
/// <summary> /// Constructor with a FileInfo object to an existing file. /// </summary> /// <param name="fileInfo"></param> /// <param name="options"></param> public static RarArchive Open(FileInfo fileInfo, RarOptions options) { fileInfo.CheckNotNull("fileInfo"); return new RarArchive(fileInfo, options); }