Bzip2Archive

Bzip2Archive constructor (1 of 3)

Initializes a new instance of the Bzip2Archive class prepared for compressing.

public Bzip2Archive()

Examples

The following example shows how to compress a file.

using (Bzip2Archive archive = new Bzip2Archive()) 
{
    archive.SetSource("data.bin");
    archive.Save("archive.bz2");
}

See Also


Bzip2Archive constructor (2 of 3)

Initializes a new instance of the Bzip2Archive class prepared for decompressing.

public Bzip2Archive(Stream sourceStream)
ParameterTypeDescription
sourceStreamStreamThe source of the archive.

Remarks

This constructor does not decompress. See Open method for decompressing.

Examples

Open an archive from a stream and extract it to a MemoryStream

var ms = new MemoryStream();
using (Bzip2Archive archive = new Bzip2Archive(File.OpenRead("archive.bz2")))
  archive.Open().CopyTo(ms);

See Also


Bzip2Archive constructor (3 of 3)

Initializes a new instance of the Bzip2Archive class prepared for decompressing.

public Bzip2Archive(string path)
ParameterTypeDescription
pathStringThe path to the archive file.

Exceptions

exceptioncondition
ArgumentNullExceptionpath is null.
SecurityExceptionThe caller does not have the required permission to access.
ArgumentExceptionThe path is empty, contains only white spaces, or contains invalid characters.
UnauthorizedAccessExceptionAccess to file path is denied.
PathTooLongExceptionThe 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.
NotSupportedExceptionFile at path contains a colon (:) in the middle of the string.
FileNotFoundExceptionThe file is not found.
DirectoryNotFoundExceptionThe specified path is invalid, such as being on an unmapped drive.
IOExceptionThe file is already open.

Remarks

This constructor does not decompress. See Open method for decompressing.

Examples

Open an archive from file by path and extract it to a MemoryStream

var ms = new MemoryStream();
using (Bzip2Archive archive = new Bzip2Archive("archive.bz2"))
  archive.Open().CopyTo(ms);

See Also