public static TryReadBlock ( BinaryReader reader, long endExtraField, |
||
reader | BinaryReader | |
endExtraField | long | |
field | ||
return | bool |
public static Zip64ExtraField GetJustZip64Block(Stream extraFieldStream, bool readUncompressedSize, bool readCompressedSize, bool readLocalHeaderOffset, bool readStartDiskNumber) { Zip64ExtraField zip64ExtraField; ZipGenericExtraField zipGenericExtraField; Zip64ExtraField zip64ExtraField1; using (BinaryReader binaryReader = new BinaryReader(extraFieldStream)) { while (ZipGenericExtraField.TryReadBlock(binaryReader, extraFieldStream.Length, out zipGenericExtraField)) { if (!Zip64ExtraField.TryGetZip64BlockFromGenericExtraField(zipGenericExtraField, readUncompressedSize, readCompressedSize, readLocalHeaderOffset, readStartDiskNumber, out zip64ExtraField)) { continue; } zip64ExtraField1 = zip64ExtraField; return(zip64ExtraField1); } zip64ExtraField = new Zip64ExtraField() { _compressedSize = null, _uncompressedSize = null, _localHeaderOffset = null, _startDiskNumber = null }; return(zip64ExtraField); } return(zip64ExtraField1); }
// There is a small chance that something very weird could happen here. The code calling into this function // will ask for a value from the extra field if the field was masked with FF's. It's theoretically possible // that a field was FF's legitimately, and the writer didn't decide to write the corresponding extra field. // Also, at the same time, other fields were masked with FF's to indicate looking in the zip64 record. // Then, the search for the zip64 record will fail because the expected size is wrong, // and a nulled out Zip64ExtraField will be returned. Thus, even though there was Zip64 data, // it will not be used. It is questionable whether this situation is possible to detect // unlike the other functions that have try-pattern semantics, these functions always return a // Zip64ExtraField. If a Zip64 extra field actually doesn't exist, all of the fields in the // returned struct will be null // // If there are more than one Zip64 extra fields, we take the first one that has the expected size // public static Zip64ExtraField GetJustZip64Block(Stream extraFieldStream, bool readUncompressedSize, bool readCompressedSize, bool readLocalHeaderOffset, bool readStartDiskNumber) { Zip64ExtraField zip64Field; using (BinaryReader reader = new BinaryReader(extraFieldStream)) { ZipGenericExtraField currentExtraField; while (ZipGenericExtraField.TryReadBlock(reader, extraFieldStream.Length, out currentExtraField)) { if (TryGetZip64BlockFromGenericExtraField(currentExtraField, readUncompressedSize, readCompressedSize, readLocalHeaderOffset, readStartDiskNumber, out zip64Field)) { return(zip64Field); } } } zip64Field = new Zip64ExtraField(); zip64Field._compressedSize = null; zip64Field._uncompressedSize = null; zip64Field._localHeaderOffset = null; zip64Field._startDiskNumber = null; return(zip64Field); }
public static List <ZipGenericExtraField> ParseExtraField(Stream extraFieldData) { ZipGenericExtraField zipGenericExtraField; List <ZipGenericExtraField> zipGenericExtraFields = new List <ZipGenericExtraField>(); using (BinaryReader binaryReader = new BinaryReader(extraFieldData)) { while (ZipGenericExtraField.TryReadBlock(binaryReader, extraFieldData.Length, out zipGenericExtraField)) { zipGenericExtraFields.Add(zipGenericExtraField); } } return(zipGenericExtraFields); }