public TarEntry(byte[] headerBuffer) { header = new TarHeader(); header.ParseBuffer(headerBuffer); }
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; }