Class LzipArchive

Class LzipArchive

Namespace: Aspose.Zip.Lzip
Assembly: Aspose.Zip.dll (25.2.0)

This class represents Lzip archive file. Use it to compose or extract Lzip archives.

public class LzipArchive : IArchive, IDisposable, IArchiveFileEntry

Inheritance

objectLzipArchive

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

LzipArchive(LzipArchiveSettings)

Initializes a new instance of the Aspose.Zip.Lzip.LzipArchive.

public LzipArchive(LzipArchiveSettings settings = null)

Parameters

settings LzipArchiveSettings

Setting of particular lzip archive with definition of dictionary size.

LzipArchive(Stream)

Initializes a new instance of the Aspose.Zip.Lzip.LzipArchive class prepared for decompressing.

public LzipArchive(Stream sourceStream)

Parameters

sourceStream Stream

The source of the archive.

Remarks

This constructor does not decompress. See Aspose.Zip.Lzip.LzipArchive.Extract(System.IO.Stream) method for decompressing.

Exceptions

ArgumentException

sourceStream is not seekable.

ArgumentNullException

sourceStream is null.

InvalidDataException

Headers do not match lzip type of archive.

LzipArchive(string)

Initializes a new instance of the Aspose.Zip.Lzip.LzipArchive class prepared for decompressing.

public LzipArchive(string path)

Parameters

path string

Path to the source of the archive.

Examples

using (FileStream extractedFile = File.Open(extractedFileName, FileMode.Create))
{
    using (var archive = new LzipArchive(sourceLzipFile))
    {
         archive.Extract(extractedFile);
       }
   }

Remarks

This constructor does not decompress. See Aspose.Zip.Lzip.LzipArchive.Extract(System.IO.Stream) method for decompressing.

Exceptions

ArgumentNullException

path is null.

SecurityException

The caller does not have the required permission to access.

ArgumentException

The path is empty, contains only white spaces, or contains invalid characters.

UnauthorizedAccessException

Access to file path is denied.

PathTooLongException

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.

NotSupportedException

File at path contains a colon (:) in the middle of the string.

FileNotFoundException

The file is not found.

DirectoryNotFoundException

The specified path is invalid, such as being on an unmapped drive.

IOException

The file is already open.

InvalidDataException

Headers do not match lzip type of archive.

Properties

Settings

Gets the setting of particular lzip archive.

public LzipArchiveSettings Settings { get; }

Property Value

LzipArchiveSettings

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 lzip archive to a stream.

public void Extract(Stream destination)

Parameters

destination Stream

Stream for storing decompressed data.

Examples

using (FileStream sourceLzipFile = File.Open(sourceFileName, FileMode.Open))
{
   using (FileStream extractedFile = File.Open(extractedFileName, FileMode.Create))
   {
        using (var archive = new LzipArchive(sourceLzipFile))
        {
               archive.Extract(extractedFile);
        }
   }
}

Exceptions

InvalidOperationException

Archive headers and service information were not read.

InvalidDataException

Error in data in header or checksum.

ArgumentNullException

Destination stream is null.

ArgumentException

Destination stream does not support writing.

Extract(FileInfo)

Extracts lzip archive to a file.

public void Extract(FileInfo fileInfo)

Parameters

fileInfo FileInfo

FileInfo for storing decompressed data.

Examples

using (FileStream lzipFile = File.Open(sourceFileName, FileMode.Open))
{
    using (var archive = new LzipArchive(lzipFile))
    {
        archive.Extract(new FileInfo("extracted.bin"));
    }
}

Exceptions

InvalidOperationException

Archive headers and service information were not read.

SecurityException

The caller does not have the required permission to open the fileInfo.

ArgumentException

File path is empty or contains only white spaces.

FileNotFoundException

The file is not found.

UnauthorizedAccessException

Path to file is read-only or is a directory.

ArgumentNullException

fileInfo is null.

DirectoryNotFoundException

The specified path is invalid, such as being on an unmapped drive.

IOException

The file is already open.

Extract(string)

Extracts lzip archive to a file by path.

public void Extract(string path)

Parameters

path string

Path to file which will store decompressed data.

Examples

using (FileStream lzipFile = File.Open(sourceFileName, FileMode.Open))
{
    using (var archive = new LzipArchive(xzFile))
    {
        archive.Extract("extracted.bin");
    }
}

Exceptions

InvalidOperationException

Archive headers and service information were not read.

ArgumentNullException

path is null.

SecurityException

The caller does not have the required permission to access.

ArgumentException

The path is empty, contains only white spaces, or contains invalid characters.

UnauthorizedAccessException

Access to file path is denied.

PathTooLongException

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.

NotSupportedException

File at path contains a colon (:) in the middle of the string.

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

ArgumentNullException

destinationDirectory is null.

PathTooLongException

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.

SecurityException

The caller does not have the required permission to access existing directory.

NotSupportedException

If directory does not exist, path contains a colon character (:) that is not part of a drive label (“C:").

ArgumentException

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 (:).

IOException

The directory specified by path is a file. -or- The network name is not known.

Save(Stream)

Saves lzip archive to the stream provided.

public void Save(Stream outputStream)

Parameters

outputStream Stream

Destination stream.

Examples

using (FileStream lzFile = File.Open("archive.lz", FileMode.Create))
{
    using (var archive = new LzipArchive())
    {
        archive.SetSource("data.bin");
        archive.Save(lzFile);
     }
}

Remarks

outputStream must be seekable.

Exceptions

ArgumentException

outputStream does not support seeking.

ArgumentNullException

outputStream is null.

Save(string)

Saves lzip archive to 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 LzipArchive()) 
{
    archive.SetSource(new FileInfo("data.bin"));
    archive.Save("result.lz");
}

Exceptions

ArgumentNullException

destinationFileName is null.

SecurityException

The caller does not have the required permission to access.

ArgumentException

The destinationFileName is empty, contains only white spaces, or contains invalid characters.

UnauthorizedAccessException

Access to file destinationFileName is denied.

PathTooLongException

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.

NotSupportedException

File at destinationFileName contains a colon (:) in the middle of the string.

Save(FileInfo)

Saves lzip archive to destination file provided.

public void Save(FileInfo destination)

Parameters

destination FileInfo

FileInfo which will be opened as destination stream.

Examples

using (var archive = new LzipArchive()) 
{
    archive.SetSource(new FileInfo("data.bin"));
    archive.Save(new FileInfo("archive.lz"));
}

Exceptions

SecurityException

The caller does not have the required permission to open the destination.

ArgumentException

File path is empty or contains only white spaces.

FileNotFoundException

The file is not found.

UnauthorizedAccessException

Path to file is read-only or is a directory.

ArgumentNullException

destination is null.

DirectoryNotFoundException

The specified path is invalid, such as being on an unmapped drive.

IOException

The file is already open.

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 LzipArchive())
   {
       archive.SetSource(new MemoryStream(new byte[] { 0x00, 0xFF }));
       archive.Save("archive.lz");
}

Exceptions

ArgumentException

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 LzipArchive()) 
{
    archive.SetSource(new FileInfo("data.bin"));
    archive.Save("archive.lz");
}

Exceptions

SecurityException

The caller does not have the required permission to open the fileInfo.

ArgumentException

File path is empty or contains only white spaces.

FileNotFoundException

The file is not found.

UnauthorizedAccessException

Path to file is read-only or is a directory.

ArgumentNullException

fileInfo is null.

DirectoryNotFoundException

The specified path is invalid, such as being on an unmapped drive.

IOException

The file is already open.

SetSource(string)

Sets the content to be compressed within the archive.

public void SetSource(string path)

Parameters

path string

Path to file to be compressed..

Examples

using (var archive = new LzipArchive()) 
{
    archive.SetSource("data.bin");
    archive.Save("archive.lz");
}

Exceptions

ArgumentNullException

path is null.

SecurityException

The caller does not have the required permission to access.

ArgumentException

The path is empty, contains only white spaces, or contains invalid characters.

UnauthorizedAccessException

Access to file path is denied.

PathTooLongException

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.

NotSupportedException

File at path contains a colon (:) in the middle of the string.

 English