Class XzArchive
Namespace: Aspose.Zip.Xz
Assembly: Aspose.Zip.dll (25.8.0)
This class represents xz archive file. Use it to compose and extract xz archives.
public class XzArchive : IArchive, IDisposable, IArchiveFileEntryInheritance
Implements
IArchive , IDisposable , IArchiveFileEntry
Inherited Members
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Constructors
XzArchive(XzArchiveSettings)
Initializes a new instance of the Aspose.Zip.Xz.XzArchive class and composes the archive in xz format.
public XzArchive(XzArchiveSettings settings = null)Parameters
settings XzArchiveSettings
Set of setting particular xz archive: dictionary size, block size, check type.
XzArchive(Stream, XzLoadOptions)
Initializes a new instance of the Aspose.Zip.Xz.XzArchive class prepared for decompressing.
public XzArchive(Stream source, XzLoadOptions options = null)Parameters
source Stream
The source of the archive.
options XzLoadOptions
Options to load the archive with.
Remarks
This constructor does not decompress. See Aspose.Zip.Xz.XzArchive.Extract(System.IO.Stream) method for decompressing.
Exceptions
source is not seekable.
source is null.
XzArchive(string, XzLoadOptions)
Initializes a new instance of the Aspose.Zip.Xz.XzArchive class prepared for decompressing.
public XzArchive(string path, XzLoadOptions options = null)Parameters
path string
Path to the source of the archive.
options XzLoadOptions
Options to load the archive with.
Remarks
This constructor does not decompress. See Aspose.Zip.Xz.XzArchive.Extract(System.IO.Stream) method for decompressing.
Exceptions
path is null.
The caller does not have the required permission to access.
The path is empty, contains only white spaces, or contains invalid characters.
Access to file path is denied.
The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
File at path contains a colon (:) in the middle of the string.
The file is not found.
The specified path is invalid, such as being on an unmapped drive.
The file is already open.
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()Dispose(bool)
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
protected virtual void Dispose(bool disposing)Parameters
disposing bool
Whether managed resources should be disposed.
Extract(Stream)
Extracts xz archive to a stream.
public void Extract(Stream destination)Parameters
destination Stream
Stream for storing decompressed data.
Examples
using (FileStream xzFile = File.Open(sourceFileName, FileMode.Open))
{
using (FileStream extractedFile = File.Open(extractedFileName, FileMode.Create))
{
using (var archive = new XzArchive(xzFile))
{
archive.Extract(extractedFile);
}
}
}Exceptions
Archive has been disposed and cannot be used.
Archive headers and service information were not read.
In .NET Framework 4.0 and above: Thrown when the extraction is canceled via the provided cancellation token.
Extract(FileInfo)
Extracts xz archive to a file.
public void Extract(FileInfo fileInfo)Parameters
fileInfo FileInfo
FileInfo for storing decompressed data.
Examples
using (FileStream xzFile = File.Open(sourceFileName, FileMode.Open))
{
using (var archive = new XzArchive(xzFile))
{
archive.Extract(new FileInfo("extracted.bin"));
}
}Exceptions
Archive has been disposed and cannot be used.
Archive headers and service information were not read.
The caller does not have the required permission to open the fileInfo.
The file path is empty or contains only white spaces.
The file is not found.
Path to file is read-only or is a directory.
fileInfo is null.
The specified path is invalid, such as being on an unmapped drive.
The file is already open.
In .NET Framework 4.0 and above: Thrown when the extraction is canceled via the provided cancellation token.
Extract(string)
Extracts xz archive to a file by path.
public FileInfo Extract(string path)Parameters
path string
Path to file which will store decompressed data.
Returns
System.IO.FileInfo instance containing extracted data.
Examples
using (FileStream xzFile = File.Open(sourceFileName, FileMode.Open))
{
using (var archive = new XzArchive(xzFile))
{
archive.Extract("extracted.bin");
}
}Exceptions
Archive has been disposed and cannot be used.
Archive headers and service information were not read.
path is null.
The caller does not have the required permission to access.
The path is empty, contains only white spaces, or contains invalid characters.
Access to file path is denied.
The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
File at path contains a colon (:) in the middle of the string.
The file is not found.
The specified path is invalid, such as being on an unmapped drive.
The file is already open.
In .NET Framework 4.0 and above: Thrown when the extraction is canceled via the provided cancellation token.
ExtractToDirectory(string)
Extracts content of the archive to the directory provided.
public void ExtractToDirectory(string destinationDirectory)Parameters
destinationDirectory string
The path to the directory to place the extracted files in.
Remarks
If the directory does not exist, it will be created.
Exceptions
Archive has been disposed and cannot be used.
destinationDirectory is null.
The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.
The caller does not have the required permission to access the existing directory.
If the directory does not exist, the path contains a colon character (:) that is not part of a drive label (“C:").
destinationDirectory is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the System.IO.Path.GetInvalidPathChars method.
-or- path is prefixed with, or contains, only a colon character (:).
The directory specified by path is a file. -or- The network name is not known.
In .NET Framework 4.0 and above: Thrown when the extraction is canceled via the provided cancellation token.
Save(Stream)
Saves xz archive to the stream provided.
public void Save(Stream output)Parameters
output Stream
Destination stream.
Examples
using (FileStream xzFile = File.Open("archive.xz", FileMode.Create))
{
using (var archive = new XzArchive())
{
archive.SetSource("data.bin");
archive.Save(xzFile);
}
}Remarks
output must be seekable.
Exceptions
Archive has been disposed and cannot be used.
output does not support seeking.
output is null.
Save(string)
Saves xz archive to the destination file provided.
public void Save(string destinationFileName)Parameters
destinationFileName string
The path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
Examples
using (var archive = new XzArchive())
{
archive.SetSource(new FileInfo("data.bin"));
archive.Save("result.xz");
}Exceptions
Archive has been disposed and cannot be used.
destinationFileName is null.
The caller does not have the required permission to access.
The destinationFileName is empty, contains only white spaces, or contains invalid characters.
Access to file destinationFileName is denied.
The specified destinationFileName, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
File at destinationFileName contains a colon (:) in the middle of the string.
SetSource(Stream)
Sets the content to be compressed within the archive.
public void SetSource(Stream source)Parameters
source Stream
The input stream for the archive.
Examples
using (var archive = new XzArchive())
{
archive.SetSource(new MemoryStream(new byte[] { 0x00, 0xFF }));
archive.Save("archive.xz");
}Exceptions
Archive has been disposed and cannot be used.
The source stream is unseekable.
SetSource(FileInfo)
Sets the content to be compressed within the archive.
public void SetSource(FileInfo fileInfo)Parameters
fileInfo FileInfo
FileInfo, which will be opened as input stream.
Examples
using (var archive = new XzArchive())
{
archive.SetSource(new FileInfo("data.bin"));
archive.Save("archive.xz");
}Exceptions
Archive has been disposed and cannot be used.
The caller does not have the required permission to open the fileInfo.
The file path is empty or contains only white spaces.
The file is not found.
Path to file is read-only or is a directory.
fileInfo is null.
The specified path is invalid, such as being on an unmapped drive.
The file is already open.
SetSource(string)
Sets the content to be compressed within the archive.
public void SetSource(string sourcePath)Parameters
sourcePath string
Path to file which will be opened as input stream.
Examples
using (var archive = new XzArchive())
{
archive.SetSource("data.bin");
archive.Save("archive.xz");
}Exceptions
Archive has been disposed and cannot be used.
sourcePath is null.
The caller does not have the required permission to access.
The sourcePath is empty, contains only white spaces, or contains invalid characters.
Access to file sourcePath is denied.
The specified sourcePath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
File at sourcePath contains a colon (:) in the middle of the string.