System.IO.Compression.Zip64ExtraField.GetAndRemoveZip64Block C# (CSharp) Method

GetAndRemoveZip64Block() public static method

public static GetAndRemoveZip64Block ( List extraFields, bool readUncompressedSize, bool readCompressedSize, bool readLocalHeaderOffset, bool readStartDiskNumber ) : Zip64ExtraField
extraFields List
readUncompressedSize bool
readCompressedSize bool
readLocalHeaderOffset bool
readStartDiskNumber bool
return Zip64ExtraField
        public static Zip64ExtraField GetAndRemoveZip64Block(List<ZipGenericExtraField> extraFields,
            bool readUncompressedSize, bool readCompressedSize,
            bool readLocalHeaderOffset, bool readStartDiskNumber)
        {
            Zip64ExtraField zip64Field = new Zip64ExtraField();

            zip64Field._compressedSize = null;
            zip64Field._uncompressedSize = null;
            zip64Field._localHeaderOffset = null;
            zip64Field._startDiskNumber = null;

            List<ZipGenericExtraField> markedForDelete = new List<ZipGenericExtraField>();
            bool zip64FieldFound = false;

            foreach (ZipGenericExtraField ef in extraFields)
            {
                if (ef.Tag == TagConstant)
                {
                    markedForDelete.Add(ef);
                    if (!zip64FieldFound)
                    {
                        if (TryGetZip64BlockFromGenericExtraField(ef, readUncompressedSize, readCompressedSize,
                                    readLocalHeaderOffset, readStartDiskNumber, out zip64Field))
                        {
                            zip64FieldFound = true;
                        }
                    }
                }
            }

            foreach (ZipGenericExtraField ef in markedForDelete)
                extraFields.Remove(ef);

            return zip64Field;
        }

Usage Example

示例#1
0
        public static bool TryReadBlock(BinaryReader reader, bool saveExtraFieldsAndComments, out ZipCentralDirectoryFileHeader header)
        {
            Zip64ExtraField justZip64Block;
            long?           uncompressedSize;
            long            value;
            long            num;
            long            value1;

            header = new ZipCentralDirectoryFileHeader();
            if (reader.ReadUInt32() != 33639248)
            {
                return(false);
            }
            header.VersionMadeBy          = reader.ReadUInt16();
            header.VersionNeededToExtract = reader.ReadUInt16();
            header.GeneralPurposeBitFlag  = reader.ReadUInt16();
            header.CompressionMethod      = reader.ReadUInt16();
            header.LastModified           = reader.ReadUInt32();
            header.Crc32 = reader.ReadUInt32();
            uint num1 = reader.ReadUInt32();
            uint num2 = reader.ReadUInt32();

            header.FilenameLength    = reader.ReadUInt16();
            header.ExtraFieldLength  = reader.ReadUInt16();
            header.FileCommentLength = reader.ReadUInt16();
            ushort num3 = reader.ReadUInt16();

            header.InternalFileAttributes = reader.ReadUInt16();
            header.ExternalFileAttributes = reader.ReadUInt32();
            uint num4 = reader.ReadUInt32();

            header.Filename = reader.ReadBytes((int)header.FilenameLength);
            bool flag     = num2 == -1;
            bool flag1    = num1 == -1;
            bool flag2    = num4 == -1;
            bool flag3    = num3 == 65535;
            long position = (long)(reader.BaseStream.Position + (ulong)header.ExtraFieldLength);

            using (Stream subReadStream = new SubReadStream(reader.BaseStream, reader.BaseStream.Position, (long)header.ExtraFieldLength))
            {
                if (!saveExtraFieldsAndComments)
                {
                    header.ExtraFields = null;
                    justZip64Block     = Zip64ExtraField.GetJustZip64Block(subReadStream, flag, flag1, flag2, flag3);
                }
                else
                {
                    header.ExtraFields = ZipGenericExtraField.ParseExtraField(subReadStream);
                    justZip64Block     = Zip64ExtraField.GetAndRemoveZip64Block(header.ExtraFields, flag, flag1, flag2, flag3);
                }
            }
            reader.BaseStream.AdvanceToPosition(position);
            if (!saveExtraFieldsAndComments)
            {
                Stream baseStream = reader.BaseStream;
                baseStream.Position = (long)(baseStream.Position + (ulong)header.FileCommentLength);
                header.FileComment  = null;
            }
            else
            {
                header.FileComment = reader.ReadBytes((int)header.FileCommentLength);
            }
            if (!justZip64Block.UncompressedSize.HasValue)
            {
                value = (long)((ulong)num2);
            }
            else
            {
                uncompressedSize = justZip64Block.UncompressedSize;
                value            = uncompressedSize.Value;
            }
            header.UncompressedSize = value;
            if (!justZip64Block.CompressedSize.HasValue)
            {
                num = (long)((ulong)num1);
            }
            else
            {
                uncompressedSize = justZip64Block.CompressedSize;
                num = uncompressedSize.Value;
            }
            header.CompressedSize = num;
            if (!justZip64Block.LocalHeaderOffset.HasValue)
            {
                value1 = (long)((ulong)num4);
            }
            else
            {
                uncompressedSize = justZip64Block.LocalHeaderOffset;
                value1           = uncompressedSize.Value;
            }
            header.RelativeOffsetOfLocalHeader = value1;
            header.DiskNumberStart             = (!justZip64Block.StartDiskNumber.HasValue ? (int)num3 : justZip64Block.StartDiskNumber.Value);
            return(true);
        }
All Usage Examples Of System.IO.Compression.Zip64ExtraField::GetAndRemoveZip64Block