Crisis.Ionic.Zip.ZipEntry.OpenReader C# (CSharp) Method

OpenReader() public method

Opens a readable stream corresponding to the zip entry in the archive. The stream decompresses and decrypts as necessary, as it is read.

DotNetZip offers a variety of ways to extract entries from a zip file. This method allows an application to extract an entry by reading a System.IO.Stream.

The return value is of type . Use it as you would any stream for reading. When an application calls on that stream, it will receive data from the zip entry that is decrypted and decompressed as necessary.

CrcCalculatorStream adds one additional feature: it keeps a CRC32 checksum on the bytes of the stream as it is read. The CRC value is available in the property on the CrcCalculatorStream. When the read is complete, your application should check this CRC against the ZipEntry.Crc property on the ZipEntry to validate the content of the ZipEntry. You don't have to validate the entry using the CRC, but you should, to verify integrity. Check the example for how to do this.

If the entry is protected with a password, then you need to provide a password prior to calling OpenReader(), either by setting the Password property on the entry, or the ZipFile.Password property on the ZipFile itself. Or, you can use OpenReader(String), the overload of OpenReader that accepts a password parameter.

If you want to extract entry data into a write-able stream that is already opened, like a System.IO.FileStream, do not use this method. Instead, use Extract(Stream).

Your application may use only one stream created by OpenReader() at a time, and you should not call other Extract methods before completing your reads on a stream obtained from OpenReader(). This is because there is really only one source stream for the compressed content. A call to OpenReader() seeks in the source stream, to the beginning of the compressed content. A subsequent call to OpenReader() on a different entry will seek to a different position in the source stream, as will a call to Extract() or one of its overloads. This will corrupt the state for the decompressing stream from the original call to OpenReader().

The OpenReader() method works only when the ZipEntry is obtained from an instance of ZipFile. This method will throw an exception if the ZipEntry is obtained from a .

public OpenReader ( ) : Crisis.Ionic.Crc.CrcCalculatorStream
return Crisis.Ionic.Crc.CrcCalculatorStream
        public Crisis.Ionic.Crc.CrcCalculatorStream OpenReader()
        {
            // workitem 10923
            if (_container.ZipFile == null)
                throw new InvalidOperationException("Use OpenReader() only with ZipFile.");

            // use the entry password if it is non-null,
            // else use the zipfile password, which is possibly null
            return InternalOpenReader(this._Password ?? this._container.Password);
        }

Same methods

ZipEntry::OpenReader ( string password ) : Crisis.Ionic.Crc.CrcCalculatorStream
ZipEntry