internal ZipArchiveEntry(ZipArchive archive, string entryName) { this._archive = archive; this._originallyInArchive = false; this._diskNumberStart = 0; this._versionToExtract = ZipVersionNeededValues.Default; this._generalPurposeBitFlag = (ZipArchiveEntry.BitFlagValues) 0; this.CompressionMethod = ZipArchiveEntry.CompressionMethodValues.Deflate; this._lastModified = DateTimeOffset.Now; this._compressedSize = (long)0; this._uncompressedSize = (long)0; this._externalFileAttr = 0; this._offsetOfLocalHeader = (long)0; this._storedOffsetOfCompressedData = null; this._crc32 = 0; this._compressedBytes = null; this._storedUncompressedData = null; this._currentlyOpenForWrite = false; this._everOpenedForWrite = false; this._outstandingWriteStream = null; this.FullName = entryName; this._cdUnknownExtraFields = null; this._lhUnknownExtraFields = null; this._fileComment = null; this._compressionLevel = null; if ((int)this._storedEntryNameBytes.Length > 65535) { throw new ArgumentException(Messages.EntryNamesTooLong); } if (this._archive.Mode == ZipArchiveMode.Create) { this._archive.AcquireArchiveStream(this); } }
internal ZipArchiveEntry(ZipArchive archive, ZipCentralDirectoryFileHeader cd) { this._archive = archive; this._originallyInArchive = true; this._diskNumberStart = cd.DiskNumberStart; this._versionToExtract = (ZipVersionNeededValues)cd.VersionNeededToExtract; this._generalPurposeBitFlag = (ZipArchiveEntry.BitFlagValues)cd.GeneralPurposeBitFlag; this.CompressionMethod = (ZipArchiveEntry.CompressionMethodValues)cd.CompressionMethod; this._lastModified = new DateTimeOffset(ZipHelper.DosTimeToDateTime(cd.LastModified)); this._compressedSize = cd.CompressedSize; this._uncompressedSize = cd.UncompressedSize; this._externalFileAttr = cd.ExternalFileAttributes; this._offsetOfLocalHeader = cd.RelativeOffsetOfLocalHeader; this._storedOffsetOfCompressedData = null; this._crc32 = cd.Crc32; this._compressedBytes = null; this._storedUncompressedData = null; this._currentlyOpenForWrite = false; this._everOpenedForWrite = false; this._outstandingWriteStream = null; this.FullName = this.DecodeEntryName(cd.Filename); this._lhUnknownExtraFields = null; this._cdUnknownExtraFields = cd.ExtraFields; this._fileComment = cd.FileComment; this._compressionLevel = null; }
private void WriteCrcAndSizesInLocalHeader(bool zip64HeaderUsed) { long position = this._archive.ArchiveStream.Position; BinaryWriter binaryWriter = new BinaryWriter(this._archive.ArchiveStream); bool flag1 = this.SizesTooLarge(); bool flag2 = flag1 && !zip64HeaderUsed; uint num1 = flag1 ? uint.MaxValue : (uint)this._compressedSize; uint num2 = flag1 ? uint.MaxValue : (uint)this._uncompressedSize; if (flag2) { this._generalPurposeBitFlag |= ZipArchiveEntry.BitFlagValues.DataDescriptor; this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader + 6L, SeekOrigin.Begin); binaryWriter.Write((ushort)this._generalPurposeBitFlag); } this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader + 14L, SeekOrigin.Begin); if (!flag2) { binaryWriter.Write(this._crc32); binaryWriter.Write(num1); binaryWriter.Write(num2); } else { binaryWriter.Write(0U); binaryWriter.Write(0U); binaryWriter.Write(0U); } if (zip64HeaderUsed) { this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader + 30L + (long)this._storedEntryNameBytes.Length + 4L, SeekOrigin.Begin); binaryWriter.Write(this._uncompressedSize); binaryWriter.Write(this._compressedSize); this._archive.ArchiveStream.Seek(position, SeekOrigin.Begin); } this._archive.ArchiveStream.Seek(position, SeekOrigin.Begin); if (!flag2) { return; } binaryWriter.Write(this._crc32); binaryWriter.Write(this._compressedSize); binaryWriter.Write(this._uncompressedSize); }
internal ZipArchiveEntry(ZipArchive archive, string entryName, FileAttributes entryFileAttributes) { this._archive = archive; this._originallyInArchive = false; this._diskNumberStart = 0; this._versionToExtract = ZipVersionNeededValues.Default; this._generalPurposeBitFlag = (ZipArchiveEntry.BitFlagValues) 0; this.CompressionMethod = ZipArchiveEntry.CompressionMethodValues.Deflate; this._lastModified = DateTimeOffset.Now; this._compressedSize = 0L; this._uncompressedSize = 0L; this._offsetOfLocalHeader = 0L; this._storedOffsetOfCompressedData = new long?(); this._crc32 = 0U; this._compressedBytes = (byte[])null; this._storedUncompressedData = (MemoryStream)null; this._currentlyOpenForWrite = false; this._everOpenedForWrite = false; this._outstandingWriteStream = (Stream)null; this.FullName = entryName; this._cdUnknownExtraFields = (List <ZipGenericExtraField>)null; this._lhUnknownExtraFields = (List <ZipGenericExtraField>)null; this._fileComment = (byte[])null; this._externalFileAttributes = (uint)entryFileAttributes; if (this._storedEntryNameBytes.Length > (int)ushort.MaxValue) { throw new ArgumentException(CompressionConstants.EntryNamesTooLong); } if (this._archive.Mode != ZipArchiveMode.Create) { return; } this._archive.AcquireArchiveStream(this); }
private bool WriteLocalFileHeader(bool isEmptyFile) { uint num; uint num1; ushort num2; ushort totalSize; ushort num3; object obj; BinaryWriter binaryWriter = new BinaryWriter(this._archive.ArchiveStream); Zip64ExtraField nullable = new Zip64ExtraField(); bool flag = false; if (isEmptyFile) { this.CompressionMethod = ZipArchiveEntry.CompressionMethodValues.Stored; num = 0; num1 = 0; } else if (this._archive.Mode == ZipArchiveMode.Create && !this._archive.ArchiveStream.CanSeek && !isEmptyFile) { this._generalPurposeBitFlag |= ZipArchiveEntry.BitFlagValues.DataDescriptor; flag = false; num = 0; num1 = 0; } else if (!this.SizesTooLarge()) { flag = false; num = (uint)this._compressedSize; num1 = (uint)this._uncompressedSize; } else { flag = true; num = -1; num1 = -1; nullable.CompressedSize = new long?(this._compressedSize); nullable.UncompressedSize = new long?(this._uncompressedSize); this.VersionToExtractAtLeast(ZipVersionNeededValues.Zip64); } this._offsetOfLocalHeader = binaryWriter.BaseStream.Position; if (flag) { totalSize = nullable.TotalSize; } else { totalSize = 0; } if (this._lhUnknownExtraFields != null) { num3 = (ushort)ZipGenericExtraField.TotalSize(this._lhUnknownExtraFields); } else { num3 = 0; } int num4 = totalSize + num3; if (num4 <= 65535) { num2 = (ushort)num4; } else { if (flag) { obj = nullable.TotalSize; } else { obj = null; } num2 = (ushort)obj; this._lhUnknownExtraFields = null; } binaryWriter.Write((uint)67324752); binaryWriter.Write((ushort)this._versionToExtract); binaryWriter.Write((ushort)this._generalPurposeBitFlag); binaryWriter.Write((ushort)this.CompressionMethod); binaryWriter.Write(ZipHelper.DateTimeToDosTime(this._lastModified.DateTime)); binaryWriter.Write(this._crc32); binaryWriter.Write(num); binaryWriter.Write(num1); binaryWriter.Write((ushort)((int)this._storedEntryNameBytes.Length)); binaryWriter.Write(num2); binaryWriter.Write(this._storedEntryNameBytes); if (flag) { nullable.WriteBlock(this._archive.ArchiveStream); } if (this._lhUnknownExtraFields != null) { ZipGenericExtraField.WriteAllBlocks(this._lhUnknownExtraFields, this._archive.ArchiveStream); } return(flag); }
private void WriteCrcAndSizesInLocalHeader(bool zip64HeaderUsed) { uint num; uint num1; long position = this._archive.ArchiveStream.Position; BinaryWriter binaryWriter = new BinaryWriter(this._archive.ArchiveStream); bool flag = this.SizesTooLarge(); bool flag1 = (!flag ? false : !zip64HeaderUsed); if (flag) { num = -1; } else { num = (uint)this._compressedSize; } uint num2 = num; if (flag) { num1 = -1; } else { num1 = (uint)this._uncompressedSize; } uint num3 = num1; if (flag1) { this._generalPurposeBitFlag |= ZipArchiveEntry.BitFlagValues.DataDescriptor; this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader + (long)6, SeekOrigin.Begin); binaryWriter.Write((ushort)this._generalPurposeBitFlag); } this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader + (long)14, SeekOrigin.Begin); if (flag1) { binaryWriter.Write((uint)0); binaryWriter.Write((uint)0); binaryWriter.Write((uint)0); } else { binaryWriter.Write(this._crc32); binaryWriter.Write(num2); binaryWriter.Write(num3); } if (zip64HeaderUsed) { this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader + (long)30 + (long)((int)this._storedEntryNameBytes.Length) + (long)4, SeekOrigin.Begin); binaryWriter.Write(this._uncompressedSize); binaryWriter.Write(this._compressedSize); this._archive.ArchiveStream.Seek(position, SeekOrigin.Begin); } this._archive.ArchiveStream.Seek(position, SeekOrigin.Begin); if (flag1) { binaryWriter.Write(this._crc32); binaryWriter.Write(this._compressedSize); binaryWriter.Write(this._uncompressedSize); } }
private bool WriteLocalFileHeader(bool isEmptyFile) { BinaryWriter binaryWriter = new BinaryWriter(this._archive.ArchiveStream); Zip64ExtraField zip64ExtraField = new Zip64ExtraField(); bool flag = false; uint num1; uint num2; if (isEmptyFile) { this.CompressionMethod = ZipArchiveEntry.CompressionMethodValues.Stored; num1 = 0U; num2 = 0U; } else if (this._archive.Mode == ZipArchiveMode.Create && !this._archive.ArchiveStream.CanSeek && !isEmptyFile) { this._generalPurposeBitFlag = this._generalPurposeBitFlag | ZipArchiveEntry.BitFlagValues.DataDescriptor; flag = false; num1 = 0U; num2 = 0U; } else if (this.SizesTooLarge()) { flag = true; num1 = uint.MaxValue; num2 = uint.MaxValue; zip64ExtraField.CompressedSize = new long?(this._compressedSize); zip64ExtraField.UncompressedSize = new long?(this._uncompressedSize); this.VersionToExtractAtLeast(ZipVersionNeededValues.Zip64); } else { flag = false; num1 = (uint)this._compressedSize; num2 = (uint)this._uncompressedSize; } this._offsetOfLocalHeader = binaryWriter.BaseStream.Position; int num3 = (flag ? (int)zip64ExtraField.TotalSize : 0) + (this._lhUnknownExtraFields != null ? ZipGenericExtraField.TotalSize(this._lhUnknownExtraFields) : 0); ushort num4; if (num3 > (int)ushort.MaxValue) { num4 = flag ? zip64ExtraField.TotalSize : (ushort)0; this._lhUnknownExtraFields = null; } else { num4 = (ushort)num3; } binaryWriter.Write(67324752U); binaryWriter.Write((ushort)this._versionToExtract); binaryWriter.Write((ushort)this._generalPurposeBitFlag); binaryWriter.Write((ushort)this.CompressionMethod); binaryWriter.Write(ZipHelper.DateTimeToDosTime(this._lastModified.DateTime)); binaryWriter.Write(this._crc32); binaryWriter.Write(num1); binaryWriter.Write(num2); binaryWriter.Write((ushort)this._storedEntryNameBytes.Length); binaryWriter.Write(num4); binaryWriter.Write(this._storedEntryNameBytes); if (flag) { zip64ExtraField.WriteBlock(this._archive.ArchiveStream); } if (this._lhUnknownExtraFields != null) { ZipGenericExtraField.WriteAllBlocks(this._lhUnknownExtraFields, this._archive.ArchiveStream); } return(flag); }