public IArchive Open(Stream stream, IFileFormat archiveFormat, IArchiveOptions archiveOptions) { if (archiveFormat is null) { stream = FileFormatFactory.Default.FromStream(stream, out archiveFormat); } if (archiveOptions is null) { archiveOptions = ArchiveOptions.Default; } if (!this.IsSupportedFileFormat(archiveFormat)) { throw new FileFormatException(IO.Properties.ExceptionMessages.UnsupportedFileFormat); } if (archiveFormat.Equals(ArchiveFormat.Zip)) { return(new SharpCompressSevenZipArchive(stream, archiveOptions)); } else if (archiveFormat.Equals(ArchiveFormat.SevenZip)) { return(new SharpCompressSevenZipArchive(stream, archiveOptions)); } else { throw new FileFormatException(IO.Properties.ExceptionMessages.UnsupportedFileFormat); } }
public IArchive Open(Stream stream, IFileFormat archiveFormat = null, IArchiveOptions archiveOptions = null) { if (archiveFormat is null) { stream = FileFormatFactory.Default.FromStream(stream, out archiveFormat); } if (archiveOptions is null) { archiveOptions = ArchiveOptions.Default; } if (!this.IsSupportedFileFormat(archiveFormat)) { throw new FileFormatException(IO.Properties.ExceptionMessages.UnsupportedFileFormat); } return(new SystemIOCompressionArchive(stream, archiveOptions)); }
public IArchive Open(Stream stream, IFileFormat archiveFormat, IArchiveOptions archiveOptions) { if (archiveFormat is null) { stream = FileFormatFactory.Default.FromStream(stream, out archiveFormat); } if (archiveOptions is null) { archiveOptions = ArchiveOptions.Default; } if (!this.IsSupportedFileFormat(archiveFormat)) { throw new FileFormatException(IO.Properties.ExceptionMessages.UnsupportedFileFormat); } return(new BinSevenZipArchive(stream, options.SevenZipDirectoryPath, archiveFormat, archiveOptions)); }
public IArchive Open(Stream stream, IFileFormat archiveFormat, IArchiveOptions archiveOptions) { if (stream is null) { throw new ArgumentNullException(nameof(stream)); } if (archiveFormat is null) { stream = FileFormatFactory.Default.FromStream(stream, out archiveFormat); } if (archiveOptions is null) { archiveOptions = ArchiveOptions.Default; } if (archiveFormat is null) { throw new FileFormatException(IO.Properties.ExceptionMessages.UnsupportedFileFormat); } List <Exception> exceptions = new List <Exception>(); IArchiveFactory archiveFactory = GetArchiveFactories() .Where(decoder => (archiveOptions.FileAccess.HasFlag(FileAccess.Write) ? decoder.GetWritableFileFormats() : decoder.GetSupportedFileFormats()).Any(format => format.Equals(archiveFormat))) .FirstOrDefault(); if (archiveFactory is object) { return(archiveFactory.Open(stream, archiveFormat, archiveOptions)); } else { // If we reach this point, we have no factories capable of reading this file format. throw new FileFormatException(archiveFormat is null ? IO.Properties.ExceptionMessages.UnsupportedFileFormat : string.Format(IO.Properties.ExceptionMessages.UnsupportedFileFormatWithFormat, archiveFormat)); } }
public IArchive Decode(Stream stream, FileAccess fileAccess = FileAccess.ReadWrite, bool leaveOpen = false, IArchiveOptions options = null) { return(new SharpCompressZipArchive(stream, fileAccess, leaveOpen, options)); }
// Public members public static IArchive Open(string filePath, FileAccess fileAccess = FileAccess.ReadWrite, IArchiveOptions options = null) { IArchiveDecoder decoder = ArchiveDecoder.FromFileExtension(filePath); if (decoder is null) { throw new UnsupportedFileFormatException(); } return(decoder.DecodeFile(filePath, fileAccess, options)); }
public static IArchive Open(Stream stream, FileAccess fileAccess = FileAccess.ReadWrite, bool leaveOpen = false, IArchiveOptions options = null) { // #todo Detect the type of the archive from the first bytes of the stream. return(CompressionPluginLoader.GetArchiveDecoders().First() .Decode(stream, fileAccess, leaveOpen, options)); }
// Public members public static IArchive Open(string filePath, IFileFormat archiveFormat, IArchiveOptions archiveOptions = null) { return(ArchiveFactory.Default.Open(filePath, archiveFormat, archiveOptions)); }
public static IArchive DecodeFile(this IArchiveDecoder archiveReader, string filePath, FileAccess fileAccess = FileAccess.ReadWrite, IArchiveOptions options = null) { FileMode fileMode = fileAccess == FileAccess.Read ? FileMode.Open : FileMode.OpenOrCreate; return(archiveReader.Decode(new FileStream(filePath, fileMode, fileAccess), fileAccess, leaveOpen: false, options)); }
public static IArchive Open(this IArchiveFactory archiveFactory, string filePath, IFileFormat archiveFormat, IArchiveOptions archiveOptions) { if (archiveFormat is null) { archiveFormat = FileFormatFactory.Default.FromFileExtension(filePath); } FileAccess fileAccess = archiveOptions?.FileAccess ?? FileAccess.ReadWrite; FileMode fileMode = fileAccess == FileAccess.Read ? FileMode.Open : FileMode.OpenOrCreate; FileStream fileStream = new FileStream(filePath, fileMode, fileAccess); try { return(archiveFactory.Open(fileStream, archiveFormat, archiveOptions)); } catch { fileStream.Dispose(); throw; } }
public static IArchive Open(this IArchiveFactory archiveFactory, string filePath, IArchiveOptions archiveOptions) { return(Open(archiveFactory, filePath, null, archiveOptions)); }
public static IArchive Open(this IArchiveFactory archiveFactory, Stream stream, IArchiveOptions archiveOptions) { if (archiveOptions is null) { archiveOptions = ArchiveOptions.Default; } stream = FileFormatFactory.Default.FromStream(stream, out IFileFormat archiveFormat); return(archiveFactory.Open(stream, archiveFormat, archiveOptions: archiveOptions)); }