// Methods internal static ZipIOLocalFileDataDescriptor CreateNew() { ZipIOLocalFileDataDescriptor descriptor = new ZipIOLocalFileDataDescriptor(); descriptor._size = 0x18; return(descriptor); }
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); }
internal static ZipIOLocalFileBlock CreateNew(ZipIOBlockManager blockManager, string fileName, CompressionMethodEnum compressionMethod, DeflateOptionEnum deflateOption) { ZipIOLocalFileBlock block = new ZipIOLocalFileBlock(blockManager, false, false); block._localFileHeader = ZipIOLocalFileHeader.CreateNew(fileName, blockManager.Encoding, compressionMethod, deflateOption, blockManager.Streaming); if (blockManager.Streaming) { block._localFileDataDescriptor = ZipIOLocalFileDataDescriptor.CreateNew(); } block._offset = 0L; block._dirtyFlag = true; block._fileItemStream = new ZipIOFileItemStream(blockManager, block, block._offset + block._localFileHeader.Size, 0L); if (compressionMethod == CompressionMethodEnum.Deflated) { block._deflateStream = new CompressStream(block._fileItemStream, 0L, true); block._crcCalculatingStream = new ProgressiveCrcCalculatingStream(blockManager, block._deflateStream); return(block); } block._crcCalculatingStream = new ProgressiveCrcCalculatingStream(blockManager, block._fileItemStream); return(block); }
public void UpdateReferences(bool closingFlag) { Invariant.Assert(!this._blockManager.Streaming); this.CheckDisposed(); if (closingFlag) { this.CloseExposedStreams(); } else { this.FlushExposedStreams(); } if (this.GetDirtyFlag(closingFlag)) { long size = this._localFileHeader.Size; long length = this._crcCalculatingStream.Length; this._localFileHeader.Crc32 = this._crcCalculatingStream.CalculateCrc(); if (closingFlag) { this._crcCalculatingStream.Close(); if (this._deflateStream != null) { this._deflateStream.Close(); } } if (this._fileItemStream.DataChanged) { this._localFileHeader.LastModFileDateTime = ZipIOBlockManager.ToMsDosDateTime(DateTime.Now); } long compressedSize = this._fileItemStream.Length; this._localFileHeader.UpdateZip64Structures(compressedSize, length, this.Offset); this._localFileHeader.UpdatePadding(this._localFileHeader.Size - size); this._localFileHeader.StreamingCreationFlag = false; this._localFileDataDescriptor = null; this._fileItemStream.Move((this.Offset + this._localFileHeader.Size) - this._fileItemStream.Offset); this._dirtyFlag = true; } }
internal static ZipIOLocalFileDataDescriptor ParseRecord(BinaryReader reader, long compressedSizeFromCentralDir, long uncompressedSizeFromCentralDir, uint crc32FromCentralDir, ushort versionNeededToExtract) { ZipIOLocalFileDataDescriptor descriptor = new ZipIOLocalFileDataDescriptor(); uint[] numArray = new uint[6]; numArray[0] = reader.ReadUInt32(); numArray[1] = reader.ReadUInt32(); numArray[2] = reader.ReadUInt32(); if (descriptor.TestMatch(0x8074b50, crc32FromCentralDir, compressedSizeFromCentralDir, uncompressedSizeFromCentralDir, 0x8074b50, numArray[0], (ulong)numArray[1], (ulong)numArray[2])) { descriptor._size = 12; return(descriptor); } numArray[3] = reader.ReadUInt32(); if (descriptor.TestMatch(0x8074b50, crc32FromCentralDir, compressedSizeFromCentralDir, uncompressedSizeFromCentralDir, numArray[0], numArray[1], (ulong)numArray[2], (ulong)numArray[3])) { descriptor._size = 0x10; return(descriptor); } if (versionNeededToExtract < 0x2d) { throw new FileFormatException(SR.Get("CorruptedData")); } numArray[4] = reader.ReadUInt32(); if (descriptor.TestMatch(0x8074b50, crc32FromCentralDir, compressedSizeFromCentralDir, uncompressedSizeFromCentralDir, 0x8074b50, numArray[0], ZipIOBlockManager.ConvertToUInt64(numArray[1], numArray[2]), ZipIOBlockManager.ConvertToUInt64(numArray[3], numArray[4]))) { descriptor._size = 20; return(descriptor); } numArray[5] = reader.ReadUInt32(); if (!descriptor.TestMatch(0x8074b50, crc32FromCentralDir, compressedSizeFromCentralDir, uncompressedSizeFromCentralDir, numArray[0], numArray[1], ZipIOBlockManager.ConvertToUInt64(numArray[2], numArray[3]), ZipIOBlockManager.ConvertToUInt64(numArray[4], numArray[5]))) { throw new FileFormatException(SR.Get("CorruptedData")); } descriptor._size = 0x18; return(descriptor); }