public TarEntry GetNextEntry() { if (_hasHitEof) { return null; } if (_currentEntry != null) { SkipToNextEntry(); } byte[] block = _tarBuffer.ReadBlock(); if (block == null) { _hasHitEof = true; } else if (TarBuffer.IsEndOfArchiveBlock(block)) { _hasHitEof = true; } if (_hasHitEof) { _currentEntry = null; } else { try { TarHeader header = new TarHeader(); header.ParseBuffer(block); if (!header.IsChecksumValid) { throw new TarException("Header checksum is invalid"); } _entryOffset = 0L; _entrySize = header.Size; StringBuilder builder = null; if (header.TypeFlag == 0x4c) { byte[] buffer = new byte[0x200]; long size = _entrySize; builder = new StringBuilder(); while (size > 0L) { int length = Read(buffer, 0, (size > buffer.Length) ? buffer.Length : ((int)size)); if (length == -1) { throw new InvalidHeaderException("Failed to read long name entry"); } builder.Append(TarHeader.ParseName(buffer, 0, length)); size -= length; } SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } else if (header.TypeFlag == 0x67) { SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } else if (header.TypeFlag == 120) { SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } else if (header.TypeFlag == 0x56) { SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } else if (((header.TypeFlag != 0x30) && (header.TypeFlag != 0)) && (header.TypeFlag != 0x35)) { SkipToNextEntry(); block = _tarBuffer.ReadBlock(); } if (_entryFactory == null) { _currentEntry = new TarEntry(block); if (builder != null) { _currentEntry.Name = builder.ToString(); } } else { _currentEntry = _entryFactory.CreateEntry(block); } _entryOffset = 0L; _entrySize = _currentEntry.Size; } catch (InvalidHeaderException exception) { _entrySize = 0L; _entryOffset = 0L; _currentEntry = null; throw new InvalidHeaderException(string.Format("Bad header in record {0} block {1} {2}", _tarBuffer.CurrentRecord, _tarBuffer.CurrentBlock, exception.Message)); } } return _currentEntry; }
public TarEntry(byte[] headerBuffer) { _header = new TarHeader(); _header.ParseBuffer(headerBuffer); }