예제 #1
0
        private void ParseRecord(BinaryReader reader,
                                 string fileName,
                                 long position,
                                 ZipIOCentralDirectoryBlock centralDir,
                                 ZipIOCentralDirectoryFileHeader centralDirFileHeader)
        {
            CheckDisposed();
            Debug.Assert(!_blockManager.Streaming, "Not legal in Streaming mode");

            _localFileHeader = ZipIOLocalFileHeader.ParseRecord(reader, _blockManager.Encoding);

            // Let's find out whether local file descriptor is there or not
            if (_localFileHeader.StreamingCreationFlag)
            {
                // seek forward by the uncompressed size
                _blockManager.Stream.Seek(centralDirFileHeader.CompressedSize, SeekOrigin.Current);
                _localFileDataDescriptor = ZipIOLocalFileDataDescriptor.ParseRecord(reader,
                                                                                    centralDirFileHeader.CompressedSize,
                                                                                    centralDirFileHeader.UncompressedSize,
                                                                                    centralDirFileHeader.Crc32,
                                                                                    _localFileHeader.VersionNeededToExtract);
            }
            else
            {
                _localFileDataDescriptor = null;
            }

            _offset    = position;
            _dirtyFlag = false;

            checked
            {
                _fileItemStream = new ZipIOFileItemStream(_blockManager,
                                                          this,
                                                          position + _localFileHeader.Size,
                                                          centralDirFileHeader.CompressedSize);
            }

            // init deflate stream if necessary
            if ((CompressionMethodEnum)_localFileHeader.CompressionMethod == CompressionMethodEnum.Deflated)
            {
                Debug.Assert(_fileItemStream.Position == 0, "CompressStream assumes base stream is at position zero");
                _deflateStream = new CompressStream(_fileItemStream, centralDirFileHeader.UncompressedSize);

                _crcCalculatingStream = new ProgressiveCrcCalculatingStream(_blockManager, _deflateStream, Crc32);
            }
            else if ((CompressionMethodEnum)_localFileHeader.CompressionMethod == CompressionMethodEnum.Stored)
            {
                _crcCalculatingStream = new ProgressiveCrcCalculatingStream(_blockManager, _fileItemStream, Crc32);
            }
            else
            {
                throw new NotSupportedException(SR.Get(SRID.ZipNotSupportedCompressionMethod));
            }

            Validate(fileName, centralDir, centralDirFileHeader);
        }
예제 #2
0
        private void ParseRecord (BinaryReader reader,
                                            string fileName,
                                            long position, 
                                            ZipIOCentralDirectoryBlock centralDir,
                                            ZipIOCentralDirectoryFileHeader centralDirFileHeader) 
        { 
            CheckDisposed();
            Debug.Assert(!_blockManager.Streaming, "Not legal in Streaming mode"); 

            _localFileHeader = ZipIOLocalFileHeader.ParseRecord(reader, _blockManager.Encoding);

            // Let's find out whether local file descriptor is there or not 
            if (_localFileHeader.StreamingCreationFlag)
            { 
                // seek forward by the uncompressed size 
                _blockManager.Stream.Seek(centralDirFileHeader.CompressedSize, SeekOrigin.Current);
                _localFileDataDescriptor = ZipIOLocalFileDataDescriptor.ParseRecord(reader, 
                                                        centralDirFileHeader.CompressedSize,
                                                        centralDirFileHeader.UncompressedSize,
                                                        centralDirFileHeader.Crc32,
                                                        _localFileHeader.VersionNeededToExtract); 
            }
            else 
            { 
                _localFileDataDescriptor = null;
            } 

            _offset = position;
            _dirtyFlag = false;
 
            checked
            { 
                _fileItemStream = new ZipIOFileItemStream(_blockManager, 
                                            this,
                                            position + _localFileHeader.Size, 
                                            centralDirFileHeader.CompressedSize);
            }

            // init deflate stream if necessary 
            if ((CompressionMethodEnum)_localFileHeader.CompressionMethod == CompressionMethodEnum.Deflated)
            { 
                Debug.Assert(_fileItemStream.Position == 0, "CompressStream assumes base stream is at position zero"); 
                _deflateStream = new CompressStream(_fileItemStream, centralDirFileHeader.UncompressedSize);
 
                _crcCalculatingStream = new ProgressiveCrcCalculatingStream(_blockManager, _deflateStream, Crc32);
            }
            else if ((CompressionMethodEnum)_localFileHeader.CompressionMethod == CompressionMethodEnum.Stored)
            { 
                _crcCalculatingStream = new ProgressiveCrcCalculatingStream(_blockManager, _fileItemStream, Crc32);
            } 
            else 
            {
                throw new NotSupportedException(SR.Get(SRID.ZipNotSupportedCompressionMethod)); 
            }

            Validate(fileName, centralDir, centralDirFileHeader);
 
        }