Class XarArchive
Namespace: Aspose.Zip.Xar
Assembly: Aspose.Zip.dll (25.2.0)
This class represents xar archive file.
public class XarArchive : IArchive, IDisposable
Inheritance
Implements
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Constructors
XarArchive(XarCompressionSettings)
Initializes a new instance of the Aspose.Zip.Xar.XarArchive class.
public XarArchive(XarCompressionSettings defaultCompressionSettings = null)
Parameters
defaultCompressionSettings
XarCompressionSettings
The default compression settings, applyed to all entries of the archive.
Examples
The following example shows how to compress a file.
using (var archive = new XarArchive())
{
archive.CreateEntry("first.bin", "data.bin");
archive.Save("archive.xar");
}
XarArchive(Stream, XarLoadOptions)
Initializes a new instance of the Aspose.Zip.Xar.XarArchive class and composes entries list can be extracted from the archive.
public XarArchive(Stream sourceStream, XarLoadOptions loadOptions = null)
Parameters
sourceStream
Stream
The source of the archive. It must be seekable.
loadOptions
XarLoadOptions
The options to load archive with.
Examples
The following example shows how to extract all of the entries to a directory.
using (var archive = new XarArchive(File.OpenRead("archive.xar")))
{
archive.ExtractToDirectory("C:\\extracted");
}
Remarks
This constructor does not unpack any entry. See Aspose.Zip.Xar.XarFileEntry.Open method for unpacking.
Exceptions
sourceStream
is null.
sourceStream
is not seekable.
sourceStream
is not valid xar archive.
XarArchive(string, XarLoadOptions)
Initializes a new instance of the Aspose.Zip.Xar.XarArchive class and composes entries list can be extracted from the archive.
public XarArchive(string path, XarLoadOptions loadOptions = null)
Parameters
path
string
The path to the archive file.
loadOptions
XarLoadOptions
The options to load archive with.
Examples
The following example shows how to extract all of the entries to a directory.
using (var archive = new XarArchive("archive.xar"))
{
archive.ExtractToDirectory("C:\\extracted");
}
Remarks
This constructor does not unpack any entry. See Aspose.Zip.Xar.XarFileEntry.Open method for unpacking.
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.
File at path
is not valid xar archive.
Properties
Entries
Gets entries of Aspose.Zip.Xar.XarEntry type constituting the archive.
public IEnumerable<xarentry> Entries { get; }
Property Value
IEnumerable<XarEntry>
Methods
CreateEntries(string, bool, XarCompressionSettings)
Adds to the archive all the files and directories recursively in the directory given.
public XarArchive CreateEntries(string sourceDirectory, bool includeRootDirectory = true, XarCompressionSettings compressionSettings = null)
Parameters
sourceDirectory
string
Directory to compress.
includeRootDirectory
bool
Indicates whether to include the root directory itself or not.
compressionSettings
XarCompressionSettings
The compression settings used for added Aspose.Zip.Xar.XarEntry items.
Returns
Xar entry instance.
Examples
using (FileStream xarFile = File.Open("archive.xar", FileMode.Create))
{
using (var archive = new XarArchive())
{
archive.CreateEntries(@"C:\folder", false);
archive.Save(xarFile);
}
}
Exceptions
sourceDirectory
is null.
The caller does not have the required permission to access sourceDirectory
.
sourceDirectory
contains invalid characters such as “, <, >, or |.
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 specified path, file name, or both are too long.
sourceDirectory
stands for a file, not for a directory.
CreateEntries(DirectoryInfo, bool, XarCompressionSettings)
Adds to the archive all the files and directories recursively in the directory given.
public XarArchive CreateEntries(DirectoryInfo directory, bool includeRootDirectory = true, XarCompressionSettings compressionSettings = null)
Parameters
directory
DirectoryInfo
Directory to compress.
includeRootDirectory
bool
Indicates whether to include the root directory itself or not.
compressionSettings
XarCompressionSettings
The compression settings used for added Aspose.Zip.Xar.XarEntry items.
Returns
Xar entry instance.
Examples
using (FileStream xarFile = File.Open("archive.xar", FileMode.Create))
{
using (var archive = new XarArchive())
{
archive.CreateEntries(new DirectoryInfo(@"C:\folder"), false);
archive.Save(xarFile);
}
}
Exceptions
directory
is null.
The caller does not have the required permission to access directory
.
directory
stands for a file, not for a directory.
CreateEntry(string, FileInfo, bool, XarCompressionSettings)
Create single entry within the archive.
public XarEntry CreateEntry(string name, FileInfo fileInfo, bool openImmediately = false, XarCompressionSettings compressionSettings = null)
Parameters
name
string
The name of the entry.
fileInfo
FileInfo
The metadata of file or folder to be compressed.
openImmediately
bool
True if open the file immediately, otherwise open the file on archive saving.
compressionSettings
XarCompressionSettings
The compression settings used for added Aspose.Zip.Xar.XarEntry item.
Returns
Xar entry instance.
Examples
FileInfo fileInfo = new FileInfo("data.bin");
using (var archive = new XarArchive())
{
archive.CreateEntry("test.bin", fileInfo);
archive.Save("archive.xar");
}
Remarks
If the file is opened immediately with openImmediately
parameter it becomes blocked until archive is disposed.
Exceptions
name
is null.
name
is empty.
fileInfo
is null.
CreateEntry(string, string, bool, XarCompressionSettings)
Create single entry within the archive.
public XarEntry CreateEntry(string name, string sourcePath, bool openImmediately = false, XarCompressionSettings compressionSettings = null)
Parameters
name
string
The name of the entry.
sourcePath
string
Path to file to be compressed.
openImmediately
bool
True if open the file immediately, otherwise open the file on archive saving.
compressionSettings
XarCompressionSettings
The compression settings used for added Aspose.Zip.Xar.XarEntry item.
Returns
Xar entry instance.
Examples
using (var archive = new XarArchive())
{
archive.CreateEntry("first.bin", "data.bin");
archive.Save("archive.xar");
}
Remarks
The entry name is solely set within name
parameter. The file name provided in sourcePath
parameter does not affect the entry name.
If the file is opened immediately with openImmediately
parameter it becomes blocked until archive is disposed.
Exceptions
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. - or - File name, as a part of name
, exceeds 100 symbols.
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. - or - name
is too long for xar.
File at sourcePath
contains a colon (:) in the middle of the string.
Impossible to modify xar archive.
CreateEntry(string, Stream, XarCompressionSettings)
Create single entry within the archive.
public XarEntry CreateEntry(string name, Stream source, XarCompressionSettings compressionSettings = null)
Parameters
name
string
The name of the entry.
source
Stream
The input stream for the entry.
compressionSettings
XarCompressionSettings
The compression settings used for added Aspose.Zip.Xar.XarEntry item.
Returns
Xar entry instance.
Examples
using (var archive = new XarArchive())
{
archive.CreateEntry("data.bin", File.OpenRead("data.bin"));
archive.Save("archive.xar");
}
Exceptions
name
is null.
source
is null.
name
is empty.
Impossible to modify xar archive.
DeleteEntry(XarEntry)
Removes the first occurrence of a specific entry from the entries list.
public XarArchive DeleteEntry(XarEntry entry)
Parameters
entry
XarEntry
The entry to remove from the entries list.
Returns
Xar entry instance.
Examples
Here is how you can remove all entries except the last one:
using (var archive = new XarArchive("archive.xar"))
{
while (archive.Entries.Count > 1)
archive.DeleteEntry(archive.Entries.FirstOrDefault());
archive.Save(outputXarFile);
}
Exceptions
entry
is null.
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.
ExtractToDirectory(string)
Extracts all the files in 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.
Examples
using (var archive = new XarArchive("archive.xar"))
{
archive.ExtractToDirectory("C:\\extracted");
}
Remarks
If the directory does not exist, it will be created.
Exceptions
path 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 existing directory.
If directory does not exist, path contains a colon character (:) that is not part of a drive label (“C:").
path 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.
Archive is corrupted.
Save(string, XarSaveOptions)
Saves archive to destination file provided.
public void Save(string destinationFileName, XarSaveOptions saveOptions = null)
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.
saveOptions
XarSaveOptions
Options to save xar archive with.
Exceptions
destinationFileName
is null.
Impossible to modify xar archive.
Save(Stream, XarSaveOptions)
Saves archive to the stream provided.
public void Save(Stream output, XarSaveOptions saveOptions = null)
Parameters
output
Stream
Destination stream.
saveOptions
XarSaveOptions
Options to save xar archive with.
Exceptions
output
is null.
output
Is not writable/readable or not seekable.
Impossible to modify xar archive.