private void CreateCentralDirectoryBlock() { this.CheckDisposed(); int index = this._blockList.IndexOf(this.Zip64EndOfCentralDirectoryBlock); this._centralDirectoryBlock = ZipIOCentralDirectoryBlock.CreateNew(this); this.InsertBlock(index, this._centralDirectoryBlock); }
internal static ZipIOCentralDirectoryBlock CreateNew(ZipIOBlockManager blockManager) { ZipIOCentralDirectoryBlock block = new ZipIOCentralDirectoryBlock(blockManager); block._offset = 0L; block._dirtyFlag = true; block._centralDirectoryDigitalSignature = null; return(block); }
internal static ZipIOCentralDirectoryBlock SeekableLoad(ZipIOBlockManager blockManager) { ZipIOZip64EndOfCentralDirectoryBlock block = blockManager.Zip64EndOfCentralDirectoryBlock; blockManager.Stream.Seek(block.OffsetOfStartOfCentralDirectory, SeekOrigin.Begin); ZipIOCentralDirectoryBlock block2 = new ZipIOCentralDirectoryBlock(blockManager); block2.ParseRecord(blockManager.BinaryReader, block.OffsetOfStartOfCentralDirectory, block.TotalNumberOfEntriesInTheCentralDirectory, block.SizeOfCentralDirectory); return(block2); }
internal static ZipIOLocalFileBlock SeekableLoad(ZipIOBlockManager blockManager, string fileName) { ZipIOCentralDirectoryBlock centralDirectoryBlock = blockManager.CentralDirectoryBlock; ZipIOCentralDirectoryFileHeader centralDirectoryFileHeader = centralDirectoryBlock.GetCentralDirectoryFileHeader(fileName); long offsetOfLocalHeader = centralDirectoryFileHeader.OffsetOfLocalHeader; bool folderFlag = centralDirectoryFileHeader.FolderFlag; bool volumeLabelFlag = centralDirectoryFileHeader.VolumeLabelFlag; blockManager.Stream.Seek(offsetOfLocalHeader, SeekOrigin.Begin); ZipIOLocalFileBlock block = new ZipIOLocalFileBlock(blockManager, folderFlag, volumeLabelFlag); block.ParseRecord(blockManager.BinaryReader, fileName, offsetOfLocalHeader, centralDirectoryBlock, centralDirectoryFileHeader); return(block); }
private void Validate(string fileName, ZipIOCentralDirectoryBlock centralDir, ZipIOCentralDirectoryFileHeader centralDirFileHeader) { if (string.CompareOrdinal(this._localFileHeader.FileName, fileName) != 0) { throw new FileFormatException(SR.Get("CorruptedData")); } if ((((this.VersionNeededToExtract != centralDirFileHeader.VersionNeededToExtract) || (this.GeneralPurposeBitFlag != centralDirFileHeader.GeneralPurposeBitFlag)) || ((this.CompressedSize != centralDirFileHeader.CompressedSize) || (this.UncompressedSize != centralDirFileHeader.UncompressedSize))) || ((this.CompressionMethod != centralDirFileHeader.CompressionMethod) || (this.Crc32 != centralDirFileHeader.Crc32))) { throw new FileFormatException(SR.Get("CorruptedData")); } if ((this.Offset + this.Size) > centralDir.Offset) { throw new FileFormatException(SR.Get("CorruptedData")); } }
protected void Dispose(bool disposing) { if ((disposing && !this._disposedFlag) && !this._propagatingFlushDisposed) { this._propagatingFlushDisposed = true; try { try { foreach (IZipIOBlock block in this._blockList) { IDisposable disposable2 = block as IDisposable; if (disposable2 != null) { disposable2.Dispose(); } } } finally { if (this._ownStream) { if (this._binaryReader != null) { this._binaryReader.Close(); } if (this._binaryWriter != null) { this._binaryWriter.Close(); } this._archiveStream.Close(); } } } finally { this._blockList = null; this._encoding = null; this._endOfCentralDirectoryBlock = null; this._centralDirectoryBlock = null; this._disposedFlag = true; this._propagatingFlushDisposed = false; } } }
private void LoadCentralDirectoryBlock() { this._centralDirectoryBlock = ZipIOCentralDirectoryBlock.SeekableLoad(this); this.MapBlock(this._centralDirectoryBlock); }
private void ParseRecord(BinaryReader reader, string fileName, long position, ZipIOCentralDirectoryBlock centralDir, ZipIOCentralDirectoryFileHeader centralDirFileHeader) { this.CheckDisposed(); this._localFileHeader = ZipIOLocalFileHeader.ParseRecord(reader, this._blockManager.Encoding); if (this._localFileHeader.StreamingCreationFlag) { this._blockManager.Stream.Seek(centralDirFileHeader.CompressedSize, SeekOrigin.Current); this._localFileDataDescriptor = ZipIOLocalFileDataDescriptor.ParseRecord(reader, centralDirFileHeader.CompressedSize, centralDirFileHeader.UncompressedSize, centralDirFileHeader.Crc32, this._localFileHeader.VersionNeededToExtract); } else { this._localFileDataDescriptor = null; } this._offset = position; this._dirtyFlag = false; this._fileItemStream = new ZipIOFileItemStream(this._blockManager, this, position + this._localFileHeader.Size, centralDirFileHeader.CompressedSize); if (this._localFileHeader.CompressionMethod == CompressionMethodEnum.Deflated) { this._deflateStream = new CompressStream(this._fileItemStream, centralDirFileHeader.UncompressedSize); this._crcCalculatingStream = new ProgressiveCrcCalculatingStream(this._blockManager, this._deflateStream, this.Crc32); } else { if (this._localFileHeader.CompressionMethod != CompressionMethodEnum.Stored) { throw new NotSupportedException(SR.Get("ZipNotSupportedCompressionMethod")); } this._crcCalculatingStream = new ProgressiveCrcCalculatingStream(this._blockManager, this._fileItemStream, this.Crc32); } this.Validate(fileName, centralDir, centralDirFileHeader); }