public ParseBuffer ( byte header ) : void | ||
header | byte | /// The tar entry header buffer to get information from. /// |
return | void |
/// <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 (this.hasHitEOF) { return null; } if (this.currentEntry != null) { SkipToNextEntry(); } byte[] headerBuf = this.buffer.ReadBlock(); if (headerBuf == null) { this.hasHitEOF = true; } else if (buffer.IsEOFBlock(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) { // POSIX global extended header // Ignore things we dont understand completely for now SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_XHDR) { // POSIX extended header // Ignore things we dont understand completely for now SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_GNU_VOLHDR) { // TODO: could show volume name when verbose SkipToNextEntry(); headerBuf = this.buffer.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 = 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); } // Magic was checked here for 'ustar' but there are multiple valid possibilities // so this is not done anymore. this.entryOffset = 0; // TODO: Review How do we resolve this discrepancy?! 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; }
/// <summary> /// Construct an entry from an archive's header bytes. File is set /// to null. /// </summary> /// <param name = "headerBuffer"> /// The header bytes from a tar archive entry. /// </param> public TarEntry(byte[] headerBuffer) { header = new TarHeader(); header.ParseBuffer(headerBuffer); }
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; }
/// <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 (this.hasHitEOF) { return null; } if (this.currEntry != null) { SkipToNextEntry(); } byte[] headerBuf = this.buffer.ReadBlock(); if (headerBuf == null) { if (this.debug) { //Console.WriteLine.WriteLine("READ NULL BLOCK"); } this.hasHitEOF = true; } else if (this.buffer.IsEOFBlock(headerBuf)) { if (this.debug) { //Console.WriteLine.WriteLine( "READ EOF BLOCK" ); } this.hasHitEOF = true; } if (this.hasHitEOF) { this.currEntry = null; } else { try { TarHeader header = new TarHeader(); header.ParseBuffer(headerBuf); this.entryOffset = 0; this.entrySize = (int)header.size; StringBuilder longName = null; if (header.typeFlag == TarHeader.LF_GNU_LONGNAME) { Console.WriteLine("TarInputStream: Long name found '" + header.name + "' size = " + header.size); // DEBUG byte[] nameBuffer = new byte[TarBuffer.BlockSize]; int numToRead = this.entrySize; longName = new StringBuilder(); while (numToRead > 0) { int numRead = this.Read(nameBuffer, 0, (numToRead > nameBuffer.Length ? nameBuffer.Length : numToRead)); if (numRead == -1) { throw new InvalidHeaderException("Failed to read long name entry"); } longName.Append(TarHeader.ParseName(nameBuffer, 0, numRead).ToString()); numToRead -= numRead; } Console.WriteLine("TarInputStream: Long name is '" + longName.ToString()); // DEBUG SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.typeFlag == TarHeader.LF_GHDR) // POSIX global extended header { // Ignore things we dont understand completely for now SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.typeFlag == TarHeader.LF_XHDR) // POSIX extended header { // Ignore things we dont understand completely for now SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.typeFlag == TarHeader.LF_GNU_VOLHDR) { // TODO could show volume name when verbose? SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.typeFlag != TarHeader.LF_NORMAL && header.typeFlag != TarHeader.LF_OLDNORM) { // Ignore things we dont understand completely for now SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } if (this.eFactory == null) { this.currEntry = new TarEntry(headerBuf); if (longName != null) { this.currEntry.TarHeader.name.Length = 0; this.currEntry.TarHeader.name.Append(longName.ToString()); } } else { this.currEntry = this.eFactory.CreateEntry(headerBuf); } // TODO -jr- ustar is not the only magic possible by any means // tar, xtar, ... if (!(headerBuf[257] == 'u' && headerBuf[258] == 's' && headerBuf[259] == 't' && headerBuf[260] == 'a' && headerBuf[261] == 'r')) { throw new InvalidHeaderException("header magic is not 'ustar', but '" + headerBuf[257] + headerBuf[258] + headerBuf[259] + headerBuf[260] + headerBuf[261] + "', or (dec) " + ((int)headerBuf[257]) + ", " + ((int)headerBuf[258]) + ", " + ((int)headerBuf[259]) + ", " + ((int)headerBuf[260]) + ", " + ((int)headerBuf[261])); } if (this.debug) { //Console.WriteLine.WriteLine("TarInputStream: SET CURRENTRY '" + this.currEntry.Name + "' size = " + this.currEntry.Size); } this.entryOffset = 0; // TODO REVIEW How do we resolve this discrepancy?! this.entrySize = (int) this.currEntry.Size; } catch (InvalidHeaderException ex) { this.entrySize = 0; this.entryOffset = 0; this.currEntry = null; throw new InvalidHeaderException("bad header in record " + this.buffer.GetCurrentBlockNum() + " block " + this.buffer.GetCurrentBlockNum() + ", " + ex.Message); } } return this.currEntry; }
/// <summary> /// Construct an entry from an archive's header bytes. File is set /// to null. /// </summary> /// <param name = "headerBuffer"> /// The header bytes from a tar archive entry. /// </param> public TarEntry(byte[] headerBuffer) { header = new TarHeader(); header.ParseBuffer(headerBuffer); }
/// <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 (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) // POSIX global extended header // Ignore things we dont understand completely for now { SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_XHDR) // POSIX extended header // Ignore things we dont understand completely for now { SkipToNextEntry(); headerBuf = this.buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_GNU_VOLHDR) { // TODO: could show volume name when verbose SkipToNextEntry(); headerBuf = this.buffer.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 = 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); } // Magic was checked here for 'ustar' but there are multiple valid possibilities // so this is not done anymore. this.entryOffset = 0; // TODO: Review How do we resolve this discrepancy?! 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 (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); }
/// <summary> /// Construct an entry from an archive's header bytes. File is set /// to null. /// </summary> /// <param name = "headerBuffer"> /// The header bytes from a tar archive entry. /// </param> /// <param name = "nameEncoding"> /// The <see cref="Encoding"/> used for the Name fields, or null for ASCII only /// </param> public TarEntry(byte[] headerBuffer, Encoding nameEncoding) { header = new TarHeader(); header.ParseBuffer(headerBuffer, nameEncoding); }
/// <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 (currEntry != null) { SkipToNextEntry(); } var headerBuf = buffer.ReadBlock(); if (headerBuf == null) { hasHitEOF = true; } else if (buffer.IsEOFBlock(headerBuf)) { hasHitEOF = true; } if (hasHitEOF) { currEntry = null; } else { try { var header = new TarHeader(); header.ParseBuffer(headerBuf); if (!header.IsChecksumValid) { throw new TarException("Header checksum is invalid"); } entryOffset = 0; entrySize = header.Size; StringBuilder longName = null; if (header.TypeFlag == TarHeader.LF_GNU_LONGNAME) { var nameBuffer = new byte[TarBuffer.BlockSize]; var numToRead = entrySize; longName = new StringBuilder(); while (numToRead > 0) { var numRead = 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 = buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_GHDR) // POSIX global extended header // Ignore things we dont understand completely for now { SkipToNextEntry(); headerBuf = buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_XHDR) // POSIX extended header // Ignore things we dont understand completely for now { SkipToNextEntry(); headerBuf = buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_GNU_VOLHDR) { // TODO: could show volume name when verbose SkipToNextEntry(); headerBuf = buffer.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 = buffer.ReadBlock(); } if (eFactory == null) { currEntry = new TarEntry(headerBuf); if (longName != null) { currEntry.Name = longName.ToString(); } } else { currEntry = eFactory.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 = currEntry.Size; } catch (InvalidHeaderException ex) { entrySize = 0; entryOffset = 0; currEntry = null; throw new InvalidHeaderException("bad header in record " + buffer.GetCurrentBlockNum() + " block " + buffer.GetCurrentBlockNum() + ", " + ex.Message); } } return(currEntry); }
public TarEntry GetNextEntry() { if (this.hasHitEOF) { return(null); } if (this.currEntry != null) { this.SkipToNextEntry(); } byte[] block = this.buffer.ReadBlock(); if (block == null) { this.hasHitEOF = true; } else if (this.buffer.IsEOFBlock(block)) { this.hasHitEOF = true; } if (this.hasHitEOF) { this.currEntry = 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.buffer.ReadBlock(); } else if (header.TypeFlag == 0x67) { this.SkipToNextEntry(); block = this.buffer.ReadBlock(); } else if (header.TypeFlag == TarHeader.LF_XHDR) { this.SkipToNextEntry(); block = this.buffer.ReadBlock(); } else if (header.TypeFlag == 0x56) { this.SkipToNextEntry(); block = this.buffer.ReadBlock(); } else if (((header.TypeFlag != 0x30) && (header.TypeFlag != 0)) && (header.TypeFlag != 0x35)) { this.SkipToNextEntry(); block = this.buffer.ReadBlock(); } if (this.eFactory == null) { this.currEntry = new TarEntry(block); if (builder != null) { this.currEntry.Name = builder.ToString(); } } else { this.currEntry = this.eFactory.CreateEntry(block); } this.entryOffset = 0L; this.entrySize = this.currEntry.Size; } catch (InvalidHeaderException exception) { this.entrySize = 0L; this.entryOffset = 0L; this.currEntry = null; throw new InvalidHeaderException(string.Concat(new object[] { "bad header in record ", this.buffer.GetCurrentBlockNum(), " block ", this.buffer.GetCurrentBlockNum(), ", ", exception.Message })); } } return(this.currEntry); }
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 (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); }
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 (true) { if (entrySize <= 0L) { this.SkipToNextEntry(); block = this.tarBuffer.ReadBlock(); break; } 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; } } 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 = this.entryFactory.CreateEntry(block); } else { this.currentEntry = new TarEntry(block); if (builder != null) { this.currentEntry.Name = builder.ToString(); } } this.entryOffset = 0L; this.entrySize = this.currentEntry.Size; } catch (InvalidHeaderException exception) { this.entrySize = 0L; this.entryOffset = 0L; this.currentEntry = null; throw new InvalidHeaderException($"Bad header in record {this.tarBuffer.CurrentRecord} block {this.tarBuffer.CurrentBlock} {exception.Message}"); } } return(this.currentEntry); }