public static string ConvertToStringExt(int flags, byte[] data) { return(ZipStrings.ConvertToStringExt(flags, data)); }
/// <summary> /// Advances to the next entry in the archive /// </summary> /// <returns> /// The next <see cref="ZipEntry">entry</see> in the archive or null if there are no more entries. /// </returns> /// <remarks> /// If the previous entry is still open <see cref="CloseEntry">CloseEntry</see> is called. /// </remarks> /// <exception cref="InvalidOperationException"> /// Input stream is closed /// </exception> /// <exception cref="ZipException"> /// Password is not set, password is invalid, compression method is invalid, /// version required to extract is not supported /// </exception> public ZipEntry GetNextEntry() { if (this.crc == null) { throw new InvalidOperationException("Closed."); } if (this.entry != null) { this.CloseEntry(); } int header = this.inputBuffer.ReadLeInt(); if (header == ZipConstants.CentralHeaderSignature || header == ZipConstants.EndOfCentralDirectorySignature || header == ZipConstants.CentralHeaderDigitalSignature || header == ZipConstants.ArchiveExtraDataSignature || header == ZipConstants.Zip64CentralFileHeaderSignature) { // No more individual entries exist this.Dispose(); return(null); } // -jr- 07-Dec-2003 Ignore spanning temporary signatures if found // Spanning signature is same as descriptor signature and is untested as yet. if ((header == ZipConstants.SpanningTempSignature) || (header == ZipConstants.SpanningSignature)) { header = this.inputBuffer.ReadLeInt(); } if (header != ZipConstants.LocalHeaderSignature) { throw new ZipException("Wrong Local header signature: 0x" + string.Format("{0:X}", header)); } var versionRequiredToExtract = (short)this.inputBuffer.ReadLeShort(); this.flags = this.inputBuffer.ReadLeShort(); this.method = this.inputBuffer.ReadLeShort(); var dostime = (uint)this.inputBuffer.ReadLeInt(); int crc2 = this.inputBuffer.ReadLeInt(); this.csize = this.inputBuffer.ReadLeInt(); this.size = this.inputBuffer.ReadLeInt(); int nameLen = this.inputBuffer.ReadLeShort(); int extraLen = this.inputBuffer.ReadLeShort(); bool isCrypted = (this.flags & 1) == 1; byte[] buffer = new byte[nameLen]; this.inputBuffer.ReadRawBuffer(buffer); string name = ZipStrings.ConvertToStringExt(this.flags, buffer); this.entry = new ZipEntry(name, versionRequiredToExtract) { Flags = this.flags, CompressionMethod = (CompressionMethod)this.method }; if ((this.flags & 8) == 0) { this.entry.Crc = crc2 & 0xFFFFFFFFL; this.entry.Size = this.size & 0xFFFFFFFFL; this.entry.CompressedSize = this.csize & 0xFFFFFFFFL; this.entry.CryptoCheckValue = (byte)((crc2 >> 24) & 0xff); } else { // This allows for GNU, WinZip and possibly other archives, the PKZIP spec // says these values are zero under these circumstances. if (crc2 != 0) { this.entry.Crc = crc2 & 0xFFFFFFFFL; } if (this.size != 0) { this.entry.Size = this.size & 0xFFFFFFFFL; } if (this.csize != 0) { this.entry.CompressedSize = this.csize & 0xFFFFFFFFL; } this.entry.CryptoCheckValue = (byte)((dostime >> 8) & 0xff); } this.entry.DosTime = dostime; // If local header requires Zip64 is true then the extended header should contain // both values. // Handle extra data if present. This can set/alter some fields of the entry. if (extraLen > 0) { byte[] extra = new byte[extraLen]; this.inputBuffer.ReadRawBuffer(extra); this.entry.ExtraData = extra; } this.entry.ProcessExtraData(true); if (this.entry.CompressedSize >= 0) { this.csize = this.entry.CompressedSize; } if (this.entry.Size >= 0) { this.size = this.entry.Size; } if (this.method == (int)CompressionMethod.Stored && (!isCrypted && this.csize != this.size || (isCrypted && this.csize - ZipConstants.CryptoHeaderSize != this.size))) { throw new ZipException("Stored, but compressed != uncompressed"); } // Determine how to handle reading of data if this is attempted. if (this.entry.IsCompressionMethodSupported()) { this.internalReader = new ReadDataHandler(this.InitialRead); } else { this.internalReader = new ReadDataHandler(this.ReadingNotSupported); } return(this.entry); }