Exemplo n.º 1
0
        public ArchiveFile(Stream archiveStream, SevenZipFormat?format = null, string libraryFilePath = null)
        {
            this.libraryFilePath = libraryFilePath;

            this.InitializeAndValidateLibrary();

            if (archiveStream == null)
            {
                throw new SevenZipException("archiveStream is null");
            }

            if (format == null)
            {
                SevenZipFormat guessedFormat;

                if (this.GuessFormatFromSignature(archiveStream, out guessedFormat))
                {
                    format = guessedFormat;
                }
                else
                {
                    throw new SevenZipException("Unable to guess format automatically");
                }
            }

            this.archive       = this.sevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format.Value]);
            this.archiveStream = new InStreamWrapper(archiveStream);
        }
Exemplo n.º 2
0
        public ArchiveFile(string archiveFilePath, string libraryFilePath = null)
        {
            this.libraryFilePath = libraryFilePath;

            this.InitializeAndValidateLibrary();

            if (!File.Exists(archiveFilePath))
            {
                throw new SevenZipException("Archive file not found");
            }

            SevenZipFormat format;
            string         extension = Path.GetExtension(archiveFilePath);

            if (this.GuessFormatFromExtension(extension, out format))
            {
                // great
            }
            else if (this.GuessFormatFromSignature(archiveFilePath, out format))
            {
                // success
            }
            else
            {
                throw new SevenZipException(Path.GetFileName(archiveFilePath) + " is not a known archive type");
            }

            this.archive       = this.sevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format]);
            this.archiveStream = new InStreamWrapper(File.OpenRead(archiveFilePath));
        }
Exemplo n.º 3
0
        public ArchiveFile(string archiveFilePath, string libraryFilePath = null)
        {
            this.libraryFilePath = libraryFilePath;

            this.InitializeAndValidateLibrary();

            if (!File.Exists(archiveFilePath))
            {
                throw new SevenZipException("Archive file not found");
            }

            string extension = Path.GetExtension(archiveFilePath);

            if (string.IsNullOrWhiteSpace(extension))
            {
                throw new SevenZipException("Unable to guess format for file: " + archiveFilePath);
            }

            string fileExtension = extension.Trim('.').ToLowerInvariant();

            if (!Formats.ExtensionFormatMapping.ContainsKey(fileExtension))
            {
                throw new SevenZipException(fileExtension + " is not a known archive type");
            }

            SevenZipFormat format = this.GuessFormatFromExtension(archiveFilePath, fileExtension);

            this.archive       = this.sevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format]);
            this.archiveStream = new InStreamWrapper(File.OpenRead(archiveFilePath));
        }
        public ArchiveFile(string archiveFilePath)
        {
            if (!File.Exists(archiveFilePath))
            {
                throw new SevenZipException("Archive file not found");
            }

            var format = GetFormat(archiveFilePath);

            this.archive       = SevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format]);
            this.archiveStream = new InStreamWrapper(File.OpenRead(archiveFilePath));
        }
Exemplo n.º 5
0
        public ArchiveFile(Stream archiveStream, SevenZipFormat format, string libraryFilePath = null)
        {
            this.libraryFilePath = libraryFilePath;

            this.InitializeAndValidateLibrary();

            if (archiveStream == null)
            {
                throw new SevenZipException("archiveStream is null");
            }

            this.archive       = this.sevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format]);
            this.archiveStream = new InStreamWrapper(archiveStream);
        }
        /// <summary>
        /// It is recommended to use 'GuessFormatFromExtension' func by the file extension to identify the file format.
        /// </summary>
        /// <param name="archiveStream"></param>
        /// <param name="format">If the format is null, will read the stream header to identify the format. but it's not always right.</param>
        public ArchiveFile(Stream archiveStream, SevenZipFormat?format = null)
        {
            if (archiveStream == null)
            {
                throw new SevenZipException("archiveStream is null");
            }

            if (format == null)
            {
                SevenZipFormat guessedFormat;

                if (GuessFormatFromSignature(archiveStream, out guessedFormat))
                {
                    format = guessedFormat;
                }
                else
                {
                    throw new SevenZipException("Unable to guess format automatically");
                }
            }

            this.archive       = SevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format.Value]);
            this.archiveStream = new InStreamWrapper(archiveStream);
        }