Class ArchiveFactory
Namespace: Aspose.Zip
Assembly: Aspose.Zip.dll (25.2.0)
Detects the archive format and creates the appropriate Aspose.Zip.IArchive object according to the type of archive.
public static class ArchiveFactory
Inheritance
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
Thrown if the directory specified by path
does not exist.
Thrown if path
is null or an empty string.
Thrown if the specified archiveFormat
is not supported or recognized.
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
An Aspose.Zip.IArchive object representing the archive.
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
An Aspose.Zip.IArchive object representing the archive.
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 encrypted archive.
Returns
An Aspose.Zip.IArchive object representing the archive.