public static IsEndOfArchiveBlock ( byte block ) : bool | ||
block | byte | The data block to check. |
return | bool |
/// <summary> /// Get the next entry in this tar archive. This will skip /// over any remaining data in the current entry, if there /// is one, and place the input stream at the header of the /// next entry, and read the header and instantiate a new /// TarEntry from the header bytes and return that entry. /// If there are no more entries in the archive, null will /// be returned to indicate that the end of the archive has /// been reached. /// </summary> /// <returns> /// The next TarEntry in the archive, or null. /// </returns> public TarEntry GetNextEntry() { if (hasHitEOF) { return(null); } if (currentEntry != null) { SkipToNextEntry(); } byte[] headerBuf = tarBuffer.ReadBlock(); if (headerBuf == null) { hasHitEOF = true; } else if (TarBuffer.IsEndOfArchiveBlock(headerBuf)) { hasHitEOF = true; } if (hasHitEOF) { currentEntry = null; } else { try { TarHeader header = new TarHeader(); header.ParseBuffer(headerBuf); if (!header.IsChecksumValid) { throw new TarException("Header checksum is invalid"); } this.entryOffset = 0; this.entrySize = header.Size; StringBuilder longName = null; if (header.TypeFlag == TarHeader.LF_GNU_LONGNAME) { byte[] nameBuffer = new byte[TarBuffer.BlockSize]; long numToRead = this.entrySize; longName = new StringBuilder(); while (numToRead > 0) { int numRead = this.Read(nameBuffer, 0, (numToRead > nameBuffer.Length ? nameBuffer.Length : (int)numToRead)); if (numRead == -1) { throw new InvalidHeaderException("Failed to read long name entry"); } longName.Append(TarHeader.ParseName(nameBuffer, 0, numRead).ToString()); numToRead -= numRead; } SkipToNextEntry(); headerBuf = this.tarBuffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_GHDR) // POSIX global extended header // Ignore things we dont understand completely for now { SkipToNextEntry(); headerBuf = this.tarBuffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_XHDR) // POSIX extended header // Ignore things we dont understand completely for now { SkipToNextEntry(); headerBuf = this.tarBuffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_GNU_VOLHDR) { // TODO: could show volume name when verbose SkipToNextEntry(); headerBuf = this.tarBuffer.ReadBlock(); } else if (header.TypeFlag != TarHeader.LF_NORMAL && header.TypeFlag != TarHeader.LF_OLDNORM && header.TypeFlag != TarHeader.LF_DIR) { // Ignore things we dont understand completely for now SkipToNextEntry(); headerBuf = tarBuffer.ReadBlock(); } if (entryFactory == null) { currentEntry = new TarEntry(headerBuf); if (longName != null) { currentEntry.Name = longName.ToString(); } } else { currentEntry = entryFactory.CreateEntry(headerBuf); } // Magic was checked here for 'ustar' but there are multiple valid possibilities // so this is not done anymore. entryOffset = 0; // TODO: Review How do we resolve this discrepancy?! entrySize = this.currentEntry.Size; } catch (InvalidHeaderException ex) { entrySize = 0; entryOffset = 0; currentEntry = null; string errorText = string.Format("Bad header in record {0} block {1} {2}", tarBuffer.CurrentRecord, tarBuffer.CurrentBlock, ex.Message); throw new InvalidHeaderException(errorText); } } return(currentEntry); }
public TarEntry GetNextEntry() { if (this.hasHitEOF) { return(null); } if (this.currentEntry != null) { this.SkipToNextEntry(); } byte[] block = this.tarBuffer.ReadBlock(); if (block == null) { this.hasHitEOF = true; } else if (TarBuffer.IsEndOfArchiveBlock(block)) { this.hasHitEOF = true; } if (this.hasHitEOF) { this.currentEntry = null; } else { try { TarHeader header = new TarHeader(); header.ParseBuffer(block); if (!header.IsChecksumValid) { throw new TarException("Header checksum is invalid"); } this.entryOffset = 0L; this.entrySize = header.Size; StringBuilder builder = null; if (header.TypeFlag == 0x4c) { byte[] buffer = new byte[0x200]; long entrySize = this.entrySize; builder = new StringBuilder(); while (entrySize > 0L) { int length = this.Read(buffer, 0, (entrySize > buffer.Length) ? buffer.Length : ((int)entrySize)); if (length == -1) { throw new InvalidHeaderException("Failed to read long name entry"); } builder.Append(TarHeader.ParseName(buffer, 0, length).ToString()); entrySize -= length; } this.SkipToNextEntry(); block = this.tarBuffer.ReadBlock(); } else if (header.TypeFlag == 0x67) { this.SkipToNextEntry(); block = this.tarBuffer.ReadBlock(); } else if (header.TypeFlag == 120) { this.SkipToNextEntry(); block = this.tarBuffer.ReadBlock(); } else if (header.TypeFlag == 0x56) { this.SkipToNextEntry(); block = this.tarBuffer.ReadBlock(); } else if (((header.TypeFlag != 0x30) && (header.TypeFlag != 0)) && (header.TypeFlag != 0x35)) { this.SkipToNextEntry(); block = this.tarBuffer.ReadBlock(); } if (this.entryFactory == null) { this.currentEntry = new TarEntry(block); if (builder != null) { this.currentEntry.Name = builder.ToString(); } } else { this.currentEntry = this.entryFactory.CreateEntry(block); } this.entryOffset = 0L; this.entrySize = this.currentEntry.Size; } catch (InvalidHeaderException exception) { this.entrySize = 0L; this.entryOffset = 0L; this.currentEntry = null; throw new InvalidHeaderException(string.Format("Bad header in record {0} block {1} {2}", this.tarBuffer.CurrentRecord, this.tarBuffer.CurrentBlock, exception.Message)); } } return(this.currentEntry); }
public TarEntry GetNextEntry() { //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Expected O, but got Unknown if (hasHitEOF) { return(null); } if (currentEntry != null) { SkipToNextEntry(); } byte[] array = tarBuffer.ReadBlock(); if (array == null) { hasHitEOF = true; } else if (TarBuffer.IsEndOfArchiveBlock(array)) { hasHitEOF = true; } if (hasHitEOF) { currentEntry = null; } else { try { TarHeader tarHeader = new TarHeader(); tarHeader.ParseBuffer(array); if (!tarHeader.IsChecksumValid) { throw new TarException("Header checksum is invalid"); } entryOffset = 0L; entrySize = tarHeader.Size; StringBuilder val = null; if (tarHeader.TypeFlag == 76) { byte[] array2 = new byte[512]; long num = entrySize; val = new StringBuilder(); while (num > 0) { int num2 = ((Stream)this).Read(array2, 0, (int)((num > array2.Length) ? array2.Length : num)); if (num2 == -1) { throw new InvalidHeaderException("Failed to read long name entry"); } val.Append(((object)TarHeader.ParseName(array2, 0, num2)).ToString()); num -= num2; } SkipToNextEntry(); array = tarBuffer.ReadBlock(); } else if (tarHeader.TypeFlag == 103) { SkipToNextEntry(); array = tarBuffer.ReadBlock(); } else if (tarHeader.TypeFlag == 120) { SkipToNextEntry(); array = tarBuffer.ReadBlock(); } else if (tarHeader.TypeFlag == 86) { SkipToNextEntry(); array = tarBuffer.ReadBlock(); } else if (tarHeader.TypeFlag != 48 && tarHeader.TypeFlag != 0 && tarHeader.TypeFlag != 53) { SkipToNextEntry(); array = tarBuffer.ReadBlock(); } if (entryFactory == null) { currentEntry = new TarEntry(array); if (val != null) { currentEntry.Name = ((object)val).ToString(); } } else { currentEntry = entryFactory.CreateEntry(array); } entryOffset = 0L; entrySize = currentEntry.Size; } catch (InvalidHeaderException ex) { entrySize = 0L; entryOffset = 0L; currentEntry = null; string message = $"Bad header in record {tarBuffer.CurrentRecord} block {tarBuffer.CurrentBlock} {((global::System.Exception)(object)ex).get_Message()}"; throw new InvalidHeaderException(message); } } return(currentEntry); }
public TarEntry GetNextEntry() { if (this.hasHitEOF) { return(null); } if (this.currentEntry != null) { SkipToNextEntry(); } byte[] headerBuf = this.buffer.ReadBlock(); if (headerBuf == null) { this.hasHitEOF = true; } else if (TarBuffer.IsEndOfArchiveBlock(headerBuf)) { this.hasHitEOF = true; } if (this.hasHitEOF) { this.currentEntry = null; } else { try { TarHeader header = new TarHeader(); header.ParseBuffer(headerBuf); if (!header.IsChecksumValid) { throw new TarException("Header checksum is invalid"); } this.entryOffset = 0; this.entrySize = header.Size; StringBuilder longName = null; if (header.TypeFlag == TarHeader.LF_GNU_LONGNAME) { byte[] nameBuffer = new byte[TarBuffer.BlockSize]; long numToRead = this.entrySize; longName = new StringBuilder(); while (numToRead > 0) { int numRead = this.Read(nameBuffer, 0, (numToRead > nameBuffer.Length ? nameBuffer.Length : (int)numToRead)); if (numRead == -1) { throw new InvalidHeaderException("Failed to read long name entry"); } longName.Append(TarHeader.ParseName(nameBuffer, 0, numRead).ToString()); numToRead -= numRead; } SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_GHDR) { SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_XHDR) { SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_GNU_VOLHDR) { SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.TypeFlag != TarHeader.LF_NORMAL && header.TypeFlag != TarHeader.LF_OLDNORM && header.TypeFlag != TarHeader.LF_DIR) { SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } if (this.entryFactory == null) { this.currentEntry = new TarEntry(headerBuf); if (longName != null) { currentEntry.Name = longName.ToString(); } } else { this.currentEntry = this.entryFactory.CreateEntry(headerBuf); } this.entryOffset = 0; this.entrySize = this.currentEntry.Size; } catch (InvalidHeaderException ex) { this.entrySize = 0; this.entryOffset = 0; this.currentEntry = null; string errorText = string.Format("Bad header in record {0} block {1} {2}", buffer.CurrentRecord, buffer.CurrentBlock, ex.Message); throw new InvalidHeaderException(errorText); } } return(this.currentEntry); }
public TarEntry GetNextEntry() { if (hasHitEOF) { return(null); } if (currentEntry != null) { SkipToNextEntry(); } byte[] array = tarBuffer.ReadBlock(); if (array == null) { hasHitEOF = true; } else if (TarBuffer.IsEndOfArchiveBlock(array)) { hasHitEOF = true; } if (hasHitEOF) { currentEntry = null; } else { try { TarHeader tarHeader = new TarHeader(); tarHeader.ParseBuffer(array); if (!tarHeader.IsChecksumValid) { throw new TarException("Header checksum is invalid"); } entryOffset = 0L; entrySize = tarHeader.Size; StringBuilder stringBuilder = null; if (tarHeader.TypeFlag == 76) { byte[] array2 = new byte[512]; long num = entrySize; stringBuilder = new StringBuilder(); while (num > 0) { int num2 = Read(array2, 0, (int)((num > array2.Length) ? array2.Length : num)); if (num2 == -1) { throw new InvalidHeaderException("Failed to read long name entry"); } stringBuilder.Append(TarHeader.ParseName(array2, 0, num2).ToString()); num -= num2; } SkipToNextEntry(); array = tarBuffer.ReadBlock(); } else if (tarHeader.TypeFlag == 103) { SkipToNextEntry(); array = tarBuffer.ReadBlock(); } else if (tarHeader.TypeFlag == 120) { SkipToNextEntry(); array = tarBuffer.ReadBlock(); } else if (tarHeader.TypeFlag == 86) { SkipToNextEntry(); array = tarBuffer.ReadBlock(); } else if (tarHeader.TypeFlag != 48 && tarHeader.TypeFlag != 0 && tarHeader.TypeFlag != 53) { SkipToNextEntry(); array = tarBuffer.ReadBlock(); } if (entryFactory == null) { currentEntry = new TarEntry(array); if (stringBuilder != null) { currentEntry.Name = stringBuilder.ToString(); } } else { currentEntry = entryFactory.CreateEntry(array); } entryOffset = 0L; entrySize = currentEntry.Size; } catch (InvalidHeaderException ex) { entrySize = 0L; entryOffset = 0L; currentEntry = null; string message = $"Bad header in record {tarBuffer.CurrentRecord} block {tarBuffer.CurrentBlock} {ex.Message}"; throw new InvalidHeaderException(message); } } return(currentEntry); }