Class ArchiveFactory

Class ArchiveFactory

Namespace: Aspose.Zip
Assembly: Aspose.Zip.dll (26.3.0)

Detects the archive format and creates the appropriate Aspose.Zip.IArchive object according to the type of archive.

public static class ArchiveFactory

Inheritance

object ArchiveFactory

Inherited Members

object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Methods

CompressDirectory(string, string, ArchiveFormat)

Compresses the specified directory into an archive file using the provided archive format.

public static void CompressDirectory(string path, string outputFileName, ArchiveFormat archiveFormat)

Parameters

path string

The path to the directory that will be compressed.

outputFileName string

Destination file name.

archiveFormat ArchiveFormat

The format of the archive to create (e.g., zip, rar, tar, etc.).

Examples

Here is an example of how to use the CompressDirectory method:

string directoryPath = @"C:\path\to\your\directory";
ArchiveInfo.ArchiveFormat format = ArchiveInfo.ArchiveFormat.Zip;
ArchiveFactory.CompressDirectory(directoryPath, "result", format);
// This will create a ZIP file with the contents of the directory at the specified path.

Remarks

This method will create an archive file at the location specified by the path parameter. The name of the archive file will typically be the directory name followed by the appropriate file extension based on the archiveFormat. The directory itself is not modified or deleted.

Exceptions

DirectoryNotFoundException

Thrown if the directory specified by path does not exist.

ArgumentException

Thrown if path is null or an empty string.

NotSupportedException

Thrown if the specified archiveFormat is not supported or recognized.

ArgumentNullException

path is null.

GetArchive(string)

Detects the archive format and creates the appropriate Aspose.Zip.IArchive object according to the type of archive specified by the given path.

public static IArchive GetArchive(string path)

Parameters

path string

The path to the archive to be analyzed.

Returns

IArchive

An Aspose.Zip.IArchive object representing the archive.

Exceptions

ArgumentNullException

path is null.

DirectoryNotFoundException

The specified path is invalid, (for example, it is on an unmapped drive).

FileNotFoundException

The file specified in path was not found.

IOException

An I/O error occurred while opening the file.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length.

UnauthorizedAccessException

path specified a directory. -or- The caller does not have the required permission.

GetArchive(Stream)

Detects the archive format and creates the appropriate Aspose.Zip.IArchive object according to the type of archive specified by the given stream.

public static IArchive GetArchive(Stream stream)

Parameters

stream Stream

The stream containing the archive data. It must be seekable.

Returns

IArchive

An Aspose.Zip.IArchive object representing the archive.

Exceptions

ArgumentException

stream is not seekable.

ArgumentNullException

stream is null.

GetArchive(Stream, string)

Detects the archive format and creates the appropriate Aspose.Zip.IArchive object according to the type of encrypted archive specified by the given stream.

public static IArchive GetArchive(Stream stream, string password)

Parameters

stream Stream

The stream containing the archive data. It must be seekable.

password string

Password to decrypt an encrypted archive.

Returns

IArchive

An Aspose.Zip.IArchive object representing the archive.

Exceptions

ArgumentException

stream is not seekable.

ArgumentNullException

stream is null.

 English