public BlockContentsSource CreateBlockContentsSourceAndSeekToFileHeadersStart(Context context, BlockHeader block) { BlockContentsSource.BlockFlags blockFlags = new BlockContentsSource.BlockFlags(block.IsCompressed, block.IsEncrypted, block.HasContiguousDataSection, block.IsDeleted); if (block.HasContiguousDataSection) { long contiguousDataInfoStart = block.Offset - 16; long fileHeadersStart = contiguousDataInfoStart - block.CompressedFileHeadersSize; var memResInfo = context.Reader.ReadMemoryResidentBlockInfo(contiguousDataInfoStart); long dataStart = fileHeadersStart - memResInfo.CompressedSize; var result = new BlockContentsSource(context.ContainerFilePath, blockFlags, dataStart, memResInfo.CompressedSize, memResInfo.UncompressedSize); context.Reader.StreamPosition = fileHeadersStart; return(result); } else { long fileHeadersStart = block.Offset - block.CompressedFileHeadersSize; context.Reader.StreamPosition = fileHeadersStart; return(new BlockContentsSource(context.ContainerFilePath, blockFlags)); } }
public void LoadFileHeaders(Context context, BlockHeader block) { BlockContentsSource blockContentsSource = this.CreateBlockContentsSourceAndSeekToFileHeadersStart(context, block); BinaryReader fileHeaderReader = context.Reader.BaseReader; try { fileHeaderReader = this.GetReaderForPotentiallyEncryptedBlock(context, fileHeaderReader, block); fileHeaderReader = this.GetReaderForPotentiallyCompressedBlock(context, fileHeaderReader, block); using (var structureReader = new ContainerFileLoaderStructureReader(fileHeaderReader, leaveOpen: fileHeaderReader == context.Reader.BaseReader)) { for (int fileIndex = 0; fileIndex < block.NumFiles; ++fileIndex) { long?errorOffset = block.IsCompressed ? default(long?) : context.Reader.StreamPosition; var fileHeader = structureReader.ReadFileHeader(); fileHeader = context.FileHeaderTransformer.Transform(fileHeader); this.verifier.VerifyFileHeader(fileHeader, block.IsCompressed, errorOffset); this.AddFileToFileSystem(context, fileHeader, blockContentsSource); } } } finally { if (fileHeaderReader != context.Reader.BaseReader) { fileHeaderReader.Dispose(); } } }