GzipArchive

GzipArchive constructor (1 of 3)

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

public GzipArchive()

Examples

The following example shows how to compress a file.

using (GzipArchive archive = new GzipArchive()) 
{
    archive.SetSource("data.bin");
    archive.Save("archive.gz");
}

See Also


GzipArchive constructor (2 of 3)

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

public GzipArchive(Stream sourceStream, bool parseHeader = false)
ParameterTypeDescription
sourceStreamStreamThe source of the archive.
parseHeaderBooleanWhether to parse stream header to figure out properties, including name. Makes sense for seekable stream only.

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 (GzipArchive archive = new GzipArchive(File.OpenRead("archive.gz")))
  archive.Open().CopyTo(ms);

See Also


GzipArchive constructor (3 of 3)

Initializes a new instance of the GzipArchive class.

public GzipArchive(string path, bool parseHeader = false)
ParameterTypeDescription
pathStringThe path to the archive file.
parseHeaderBooleanWhether to parse stream header to figure out properties, including name. Makes sense for seekable stream only.

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.

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 (GzipArchive archive = new GzipArchive("archive.gz"))
  archive.Open().CopyTo(ms);

See Also