ZipArchive Constructor (Stream, ZipArchiveMode, Boolean, Encoding)

ZipArchive Constructor (Stream^, ZipArchiveMode, Boolean, Encoding^)

.NET Framework (current version)
 

Initializes a new instance of the ZipArchive class on the specified stream for the specified mode, uses the specified encoding for entry names, and optionally leaves the stream open.

Namespace:   System.IO.Compression
Assembly:  System.IO.Compression (in System.IO.Compression.dll)

public:
ZipArchive(
	Stream^ stream,
	ZipArchiveMode mode,
	bool leaveOpen,
	Encoding^ entryNameEncoding
)

Parameters

stream
Type: System.IO::Stream^

The input or output stream.

mode
Type: System.IO.Compression::ZipArchiveMode

One of the enumeration values that indicates whether the zip archive is used to read, create, or update entries.

leaveOpen
Type: System::Boolean

true to leave the stream open after the ZipArchive object is disposed; otherwise, false.

entryNameEncoding
Type: System.Text::Encoding^

The encoding to use when reading or writing entry names in this archive. Specify a value for this parameter only when an encoding is required for interoperability with zip archive tools and libraries that do not support UTF-8 encoding for entry names.

Exception Condition
ArgumentException

The stream is already closed, or the capabilities of the stream do not match the mode.

ArgumentNullException

stream is null.

ArgumentOutOfRangeException

mode is an invalid value.

InvalidDataException

The contents of the stream could not be interpreted as a zip archive.

-or-

mode is Update and an entry is missing from the archive or is corrupt and cannot be read.

-or-

mode is Update and an entry is too large to fit into memory.

If the mode parameter is set to Read, the stream must support reading. If the mode parameter is set to Create, the stream must support writing. If the mode parameter is set to Update, the stream must support reading, writing, and seeking.

When you open a zip archive file for reading and entryNameEncoding is set to null, entry names are decoded according to the following rules:

  • When the language encoding flag (in the general-purpose bit flag of the local file header) is not set, the current system default code page is used to decode the entry name.

  • When the language encoding flag is set, UTF-8 is used to decode the entry name.

When you open a zip archive file for reading and entryNameEncoding is set to a value other than null, entry names are decoded according to the following rules:

  • When the language encoding flag is not set, the specified entryNameEncoding is used to decode the entry name.

  • When the language encoding flag is set, UTF-8 is used to decode the entry name.

When you write to archive files and entryNameEncoding is set to null, entry names are encoded according to the following rules:

  • For entry names that contain characters outside the ASCII range, the language encoding flag is set, and entry names are encoded by using UTF-8.

  • For entry names that contain only ASCII characters, the language encoding flag is not set, and entry names are encoded by using the current system default code page.

When you write to archive files and entryNameEncoding is set to a value other than null, the specified entryNameEncoding is used to encode the entry names into bytes. The language encoding flag (in the general-purpose bit flag of the local file header) is set only when the specified encoding is a UTF-8 encoding.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft