GZipStream::Read Method (array<Byte>^, Int32, Int32)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Reads a number of decompressed bytes into the specified byte array.

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

virtual int Read(
	array<unsigned char>^ array,
	int offset,
	int count
) override


Type: array<System::Byte>^

The array used to store decompressed bytes.

Type: System::Int32

The byte offset in array at which the read bytes will be placed.

Type: System::Int32

The maximum number of decompressed bytes to read.

Return Value

Type: System::Int32

The number of bytes that were decompressed into the byte array. If the end of the stream has been reached, zero or the number of bytes read is returned.

Exception Condition

array is null.


The CompressionMode value was Compress when the object was created.

- or -

The underlying stream does not support reading.


offset or count is less than zero.


array length minus the index starting point is less than count.


The data is in an invalid format.


The stream is closed.

If data is found in an invalid format, an InvalidDataException is thrown as one of the last operations. A cyclic redundancy check (CRC) is performed as one of the last operations of this method.

The following example shows how to compress and decompress bytes by using the Read and Write methods.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1
Return to top