The TarBuffer class implements the tar archive concept of a buffered input stream. This concept goes back to the days of blocked tape drives and special io devices. In the C# universe, the only real function that this class performs is to ensure that files have the correct "record" size, or other tars will complain.

You should never have a need to access this class directly. TarBuffers are created by Tar IO Streams.

Ejemplo n.º 1
0
        /// <summary>
        /// Construct TarOutputStream with user specified block factor
        /// </summary>
        /// <param name="outputStream">stream to write to</param>
        /// <param name="blockFactor">blocking factor</param>
        public TarOutputStream(Stream outputStream, int blockFactor)
        {
            if (outputStream == null) {
                throw new ArgumentNullException(nameof(outputStream));
            }

            this.outputStream = outputStream;
            buffer = TarBuffer.CreateOutputTarBuffer(outputStream, blockFactor);

            assemblyBuffer = new byte[TarBuffer.BlockSize];
            blockBuffer = new byte[TarBuffer.BlockSize];
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Construct TarBuffer for writing Tar output to streams.
        /// </summary>
        /// <param name="outputStream">Output stream to write to.</param>
        /// <param name="blockFactor">Blocking factor to apply</param>
        /// <returns>A new <see cref="TarBuffer"/> suitable for output.</returns>
        public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockFactor)
        {
            if (outputStream == null)
            {
                throw new ArgumentNullException("outputStream");
            }

            if (blockFactor <= 0)
            {
#if NETCF_1_0
                throw new ArgumentOutOfRangeException("blockFactor");
#else
                throw new ArgumentOutOfRangeException("blockFactor", "Factor cannot be negative");
#endif
            }

            TarBuffer tarBuffer = new TarBuffer();
            tarBuffer.inputStream  = null;
            tarBuffer.outputStream = outputStream;
            tarBuffer.Initialize(blockFactor);

            return(tarBuffer);
        }
Ejemplo n.º 3
0
 public TarEntry GetNextEntry()
 {
     if (this.hasHitEOF)
     {
         return(null);
     }
     if (this.currentEntry != null)
     {
         this.SkipToNextEntry();
     }
     byte[] array = this.buffer.ReadBlock();
     if (array == null)
     {
         this.hasHitEOF = true;
     }
     else if (TarBuffer.IsEndOfArchiveBlock(array))
     {
         this.hasHitEOF = true;
     }
     if (this.hasHitEOF)
     {
         this.currentEntry = null;
     }
     else
     {
         try
         {
             TarHeader tarHeader = new TarHeader();
             tarHeader.ParseBuffer(array);
             if (!tarHeader.IsChecksumValid)
             {
                 throw new TarException("Header checksum is invalid");
             }
             this.entryOffset = 0L;
             this.entrySize   = tarHeader.Size;
             StringBuilder stringBuilder = null;
             if (tarHeader.TypeFlag == 76)
             {
                 byte[] array2 = new byte[512];
                 long   num    = this.entrySize;
                 stringBuilder = new StringBuilder();
                 while (num > 0L)
                 {
                     int num2 = this.Read(array2, 0, (num > (long)array2.Length) ? array2.Length : ((int)num));
                     if (num2 == -1)
                     {
                         throw new InvalidHeaderException("Failed to read long name entry");
                     }
                     stringBuilder.Append(TarHeader.ParseName(array2, 0, num2).ToString());
                     num -= (long)num2;
                 }
                 this.SkipToNextEntry();
                 array = this.buffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag == 103)
             {
                 this.SkipToNextEntry();
                 array = this.buffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag == 120)
             {
                 this.SkipToNextEntry();
                 array = this.buffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag == 86)
             {
                 this.SkipToNextEntry();
                 array = this.buffer.ReadBlock();
             }
             else if (tarHeader.TypeFlag != 48 && tarHeader.TypeFlag != 0 && tarHeader.TypeFlag != 53)
             {
                 this.SkipToNextEntry();
                 array = this.buffer.ReadBlock();
             }
             if (this.entryFactory == null)
             {
                 this.currentEntry = new TarEntry(array);
                 if (stringBuilder != null)
                 {
                     this.currentEntry.Name = stringBuilder.ToString();
                 }
             }
             else
             {
                 this.currentEntry = this.entryFactory.CreateEntry(array);
             }
             this.entryOffset = 0L;
             this.entrySize   = this.currentEntry.Size;
         }
         catch (InvalidHeaderException ex)
         {
             this.entrySize    = 0L;
             this.entryOffset  = 0L;
             this.currentEntry = null;
             string message = string.Format("Bad header in record {0} block {1} {2}", this.buffer.CurrentRecord, this.buffer.CurrentBlock, ex.Message);
             throw new InvalidHeaderException(message);
         }
     }
     return(this.currentEntry);
 }
Ejemplo n.º 4
0
		public TarOutputStream(Stream outputStream, int blockFactor)
		{
			this.outputStream = outputStream;
			this.buffer       = TarBuffer.CreateOutputTarBuffer(outputStream, blockFactor);
			
			this.debug     = false;
			this.assemLen  = 0;
			this.assemBuf  = new byte[TarBuffer.BlockSize];
			this.blockBuf = new byte[TarBuffer.BlockSize];
		}
Ejemplo n.º 5
0
 /// <summary>
 /// Construct a TarInputStream with user specified block factor
 /// </summary>
 /// <param name="inputStream">stream to source data from</param>
 /// <param name="blockFactor">block factor to apply to archive</param>
 public TarInputStream(Stream inputStream, int blockFactor)
 {
     this.inputStream = inputStream;
     tarBuffer = TarBuffer.CreateInputTarBuffer(inputStream, blockFactor);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Construct TarBuffer for writing Tar output to streams.
        /// </summary>
        /// <param name="outputStream">Output stream to write to.</param>
        /// <param name="blockFactor">Blocking factor to apply</param>
        /// <returns>A new <see cref="TarBuffer"/> suitable for output.</returns>
        public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockFactor)
        {
            if ( outputStream == null )
            {
                throw new ArgumentNullException("outputStream");
            }

            if ( blockFactor <= 0 )
            {
            #if NETCF_1_0
                throw new ArgumentOutOfRangeException("blockFactor");
            #else
                throw new ArgumentOutOfRangeException("blockFactor", "Factor cannot be negative");
            #endif
            }

            TarBuffer tarBuffer = new TarBuffer();
            tarBuffer.inputStream  = null;
            tarBuffer.outputStream = outputStream;
            tarBuffer.Initialize(blockFactor);

            return tarBuffer;
        }
Ejemplo n.º 7
0
 public TarEntry GetNextEntry()
 {
     if (hasHitEOF)
     {
         return(null);
     }
     if (currentEntry != null)
     {
         SkipToNextEntry();
     }
     byte[] array = tarBuffer.ReadBlock();
     if (array == null)
     {
         hasHitEOF = true;
     }
     else
     {
         hasHitEOF |= TarBuffer.IsEndOfArchiveBlock(array);
     }
     if (!hasHitEOF)
     {
         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 != 49 && tarHeader.TypeFlag != 50 && 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;
             throw new InvalidHeaderException($"Bad header in record {tarBuffer.CurrentRecord} block {tarBuffer.CurrentBlock} {ex.Message}");
         }
     }
     else
     {
         currentEntry = null;
     }
     return(currentEntry);
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
		public TarInputStream(Stream inputStream, int blockFactor)
		{
			this.inputStream = inputStream;
			this.buffer      = TarBuffer.CreateInputTarBuffer(inputStream, blockFactor);
			
			this.readBuf   = null;
			this.debug     = false;
			this.hasHitEOF = false;
			this.eFactory  = null;
		}
Ejemplo n.º 10
0
        /// <summary>
        /// Construct TarBuffer for writing Tar output to streams.
        /// </summary>
        /// <param name="outputStream">Output stream to write to.</param>
        /// <param name="blockFactor">Blocking factor to apply</param>
        /// <returns>A new <see cref="TarBuffer"/> suitable for output.</returns>
        public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockFactor)
        {
            if ( outputStream == null )
            {
                throw new ArgumentNullException("outputStream");
            }

            if ( blockFactor <= 0 )
            {

                throw new ArgumentOutOfRangeException("blockFactor");
            }

            TarBuffer tarBuffer = new TarBuffer();
            tarBuffer.inputStream  = null;
            tarBuffer.outputStream = outputStream;
            tarBuffer.Initialize(blockFactor);

            return tarBuffer;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Construct TarBuffer for writing Tar output to streams.
        /// </summary>
        /// <param name="outputStream">Output stream to write to.</param>
        /// <param name="blockFactor">Blocking factor to apply</param>
        /// <returns>A new <see cref="TarBuffer"/> suitable for output.</returns>
        public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockFactor)
        {
            if (outputStream == null) {
                throw new ArgumentNullException(nameof(outputStream));
            }

            if (blockFactor <= 0) {
                throw new ArgumentOutOfRangeException(nameof(blockFactor), "Factor cannot be negative");
            }

            var tarBuffer = new TarBuffer();
            tarBuffer.inputStream = null;
            tarBuffer.outputStream = outputStream;
            tarBuffer.Initialize(blockFactor);

            return tarBuffer;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Construct a TarInputStream with user specified block factor
 /// </summary>
 /// <param name="inputStream">stream to source data from</param>
 /// <param name="blockFactor">block factor to apply to archive</param>
 /// <param name="nameEncoding">The <see cref="Encoding"/> used for the Name fields, or null for ASCII only</param>
 public TarInputStream(Stream inputStream, int blockFactor, Encoding nameEncoding)
 {
     this.inputStream = inputStream;
     tarBuffer        = TarBuffer.CreateInputTarBuffer(inputStream, blockFactor);
     encoding         = nameEncoding;
 }
Ejemplo n.º 13
0
 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);
 }
Ejemplo n.º 14
0
        /// <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);
        }
Ejemplo n.º 15
0
		/// <summary>
		/// Construct TarBuffer for writing Tar output to streams.
		/// </summary>
		/// <param name="outputStream">Output stream to write to.</param>
		/// <param name="blockFactor">Blocking factor to apply</param>
		/// <returns>TarBuffer</returns>
		public static TarBuffer CreateOutputTarBuffer(Stream outputStream, int blockFactor)
		{
			TarBuffer tarBuffer = new TarBuffer();
			tarBuffer.inputStream  = null;
			tarBuffer.outputStream = outputStream;
			tarBuffer.Initialize(blockFactor);
			
			return tarBuffer;
		}
Ejemplo n.º 16
0
 /// <summary>
 /// Construct a TarInputStream with user specified block factor
 /// </summary>
 /// <param name="inputStream">stream to source data from</param>
 /// <param name="blockFactor">block factor to apply to archive</param>
 public TarInputStream(Stream inputStream, int blockFactor)
 {
     this.inputStream = inputStream;
     tarBuffer        = TarBuffer.CreateInputTarBuffer(inputStream, blockFactor);
 }
Ejemplo n.º 17
0
 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);
 }