System.IO.Compression.ZipArchiveFile.OpenRead C# (CSharp) Méthode

OpenRead() public méthode

Opens the archiveFile represented by the ZipArchiveFile and returns a stream that can use to read (binary) data.
public OpenRead ( ) : Stream
Résultat Stream
        public Stream OpenRead()
        {
            if (_uncompressedData == null)
            {
                if (_compressedData == null)
                {
                    // TODO if we had a rangeStream, we could avoid this copy.
                    _compressedData = new byte[_compressedLength];
                    _archive.FromStream.Seek(_positionOfCompressedDataInArchive, SeekOrigin.Begin);
                    _archive.FromStream.Read(_compressedData, 0, _compressedLength);
                }
                MemoryStream compressedReader = new MemoryStream(_compressedData);
                if (_compressionMethod == CompressionMethod.None)
                {
                    return compressedReader;
                }
                else
                {
                    return new DeflateStream(compressedReader, CompressionMode.Decompress);
                }
            }
            else
            {
                if (_uncompressedData.CanWrite)
                {
                    throw new InvalidOperationException("ZipArchiveFile still open for writing.");
                }
                return new MemoryStream(_uncompressedData.GetBuffer(), 0, (int)_uncompressedData.Length, false);
            }
        }