ZipArchive Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the ZipArchive class.
Overloads
ZipArchive(Stream) |
Initializes a new instance of the ZipArchive class from the specified stream. |
ZipArchive(Stream, ZipArchiveMode) |
Initializes a new instance of the ZipArchive class from the specified stream and with the specified mode. |
ZipArchive(Stream, ZipArchiveMode, Boolean) |
Initializes a new instance of the ZipArchive class on the specified stream for the specified mode, and optionally leaves the stream open. |
ZipArchive(Stream, ZipArchiveMode, Boolean, Encoding) |
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. |
ZipArchive(Stream)
- Source:
- ZipArchive.cs
- Source:
- ZipArchive.cs
- Source:
- ZipArchive.cs
Initializes a new instance of the ZipArchive class from the specified stream.
public:
ZipArchive(System::IO::Stream ^ stream);
public ZipArchive (System.IO.Stream stream);
new System.IO.Compression.ZipArchive : System.IO.Stream -> System.IO.Compression.ZipArchive
Public Sub New (stream As Stream)
Parameters
- stream
- Stream
The stream that contains the archive to be read.
Exceptions
The stream is already closed or does not support reading.
stream
is null
.
The contents of the stream are not in the zip archive format.
Applies to
ZipArchive(Stream, ZipArchiveMode)
- Source:
- ZipArchive.cs
- Source:
- ZipArchive.cs
- Source:
- ZipArchive.cs
Initializes a new instance of the ZipArchive class from the specified stream and with the specified mode.
public:
ZipArchive(System::IO::Stream ^ stream, System::IO::Compression::ZipArchiveMode mode);
public ZipArchive (System.IO.Stream stream, System.IO.Compression.ZipArchiveMode mode);
new System.IO.Compression.ZipArchive : System.IO.Stream * System.IO.Compression.ZipArchiveMode -> System.IO.Compression.ZipArchive
Public Sub New (stream As Stream, mode As ZipArchiveMode)
Parameters
- stream
- Stream
The input or output stream.
- mode
- ZipArchiveMode
One of the enumeration values that indicates whether the zip archive is used to read, create, or update entries.
Exceptions
The stream is already closed, or the capabilities of the stream do not match the mode.
stream
is null
.
mode
is an invalid value.
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.
Remarks
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.
Applies to
ZipArchive(Stream, ZipArchiveMode, Boolean)
- Source:
- ZipArchive.cs
- Source:
- ZipArchive.cs
- Source:
- ZipArchive.cs
Initializes a new instance of the ZipArchive class on the specified stream for the specified mode, and optionally leaves the stream open.
public:
ZipArchive(System::IO::Stream ^ stream, System::IO::Compression::ZipArchiveMode mode, bool leaveOpen);
public ZipArchive (System.IO.Stream stream, System.IO.Compression.ZipArchiveMode mode, bool leaveOpen);
new System.IO.Compression.ZipArchive : System.IO.Stream * System.IO.Compression.ZipArchiveMode * bool -> System.IO.Compression.ZipArchive
Public Sub New (stream As Stream, mode As ZipArchiveMode, leaveOpen As Boolean)
Parameters
- stream
- Stream
The input or output stream.
- mode
- ZipArchiveMode
One of the enumeration values that indicates whether the zip archive is used to read, create, or update entries.
- leaveOpen
- Boolean
true
to leave the stream open after the ZipArchive object is disposed; otherwise, false
.
Exceptions
The stream is already closed, or the capabilities of the stream do not match the mode.
stream
is null
.
mode
is an invalid value.
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.
Remarks
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.
Applies to
ZipArchive(Stream, ZipArchiveMode, Boolean, Encoding)
- Source:
- ZipArchive.cs
- Source:
- ZipArchive.cs
- Source:
- ZipArchive.cs
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.
public:
ZipArchive(System::IO::Stream ^ stream, System::IO::Compression::ZipArchiveMode mode, bool leaveOpen, System::Text::Encoding ^ entryNameEncoding);
public ZipArchive (System.IO.Stream stream, System.IO.Compression.ZipArchiveMode mode, bool leaveOpen, System.Text.Encoding entryNameEncoding);
public ZipArchive (System.IO.Stream stream, System.IO.Compression.ZipArchiveMode mode, bool leaveOpen, System.Text.Encoding? entryNameEncoding);
new System.IO.Compression.ZipArchive : System.IO.Stream * System.IO.Compression.ZipArchiveMode * bool * System.Text.Encoding -> System.IO.Compression.ZipArchive
Public Sub New (stream As Stream, mode As ZipArchiveMode, leaveOpen As Boolean, entryNameEncoding As Encoding)
Parameters
- stream
- Stream
The input or output stream.
- mode
- ZipArchiveMode
One of the enumeration values that indicates whether the zip archive is used to read, create, or update entries.
- leaveOpen
- Boolean
true
to leave the stream open after the ZipArchive object is disposed; otherwise, false
.
- entryNameEncoding
- Encoding
The encoding to use when reading or writing entry names and comments 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 or comments.
Exceptions
The stream is already closed, or the capabilities of the stream do not match the mode.
-or-
An encoding other than UTF-8 is specified for the entryNameEncoding
.
stream
is null
.
mode
is an invalid value.
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.
Remarks
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 and comments 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 and comment.
When the language encoding flag is set, UTF-8 is used to decode the entry name and comment.
When you open a zip archive file for reading and entryNameEncoding
is set to a value other than null
, entry names and comments 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 and comment.When the language encoding flag is set, UTF-8 is used to decode the entry name and comment.
When you write to archive files and entryNameEncoding
is set to null
, entry names and comments are encoded according to the following rules:
For entry names and comments that contain characters outside the ASCII range, the language encoding flag is set, and entry names and comments are encoded by using UTF-8.
For entry names and comments that contain only ASCII characters, the language encoding flag is not set, and entry names and comments 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 and comments 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.