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)
Parameter Type Description
sourceStream Stream The source of the archive.
parseHeader Boolean Whether 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)
Parameter Type Description
path String The path to the archive file.
parseHeader Boolean Whether to parse stream header to figure out properties, including name. Makes sense for seekable stream only.

Exceptions

exception condition
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.

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