public static EOCD Parse(Byte[] bytes) { var pos = FindEOCD(bytes); using (var ms = new MemoryStream(bytes, pos, bytes.Length - pos, false)) using (var r = new BinaryReader(ms)) { var sig = r.ReadInt32(); if (sig != 0x06054b50) { throw new ZipParseException("invalid eocd signature: " + sig); } var eocd = new EOCD { NumberOfThisDisk = r.ReadUInt16(), DiskWhereCentralDirectoryStarts = r.ReadUInt16(), NumberOfCentralDirectoryRecordsOnThisDisk = r.ReadUInt16(), TotalNumberOfCentralDirectoryRecords = r.ReadUInt16(), SizeOfCentralDirectoryBytes = r.ReadInt32(), OffsetOfStartOfCentralDirectory = r.ReadInt32(), }; var commentLength = r.ReadUInt16(); var commentBytes = r.ReadBytes(commentLength); eocd.Comment = Encoding.ASCII.GetString(commentBytes); return(eocd); } }
public static ZipArchiveStorage Parse(byte[] bytes) { var eocd = EOCD.Parse(bytes); var archive = new ZipArchiveStorage(); var pos = eocd.OffsetOfStartOfCentralDirectory; for (int i = 0; i < eocd.NumberOfCentralDirectoryRecordsOnThisDisk; ++i) { var file = new CentralDirectoryFileHeader(bytes, pos); archive.Entries.Add(file); pos += file.Length; } return(archive); }