当前位置: 首页>>代码示例>>C#>>正文


C# TarHeader.ParseBuffer方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Tar.TarHeader.ParseBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# TarHeader.ParseBuffer方法的具体用法?C# TarHeader.ParseBuffer怎么用?C# TarHeader.ParseBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Tar.TarHeader的用法示例。


在下文中一共展示了TarHeader.ParseBuffer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TarEntry

		/// <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);
		}
开发者ID:lPinchol,项目名称:Reign-Unity-Plugin,代码行数:12,代码来源:TarEntry.cs

示例2: GetNextEntry

		/// <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();
//.........这里部分代码省略.........
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:101,代码来源:TarInputStream.cs

示例3: GetNextEntry

		/// <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;
					
//.........这里部分代码省略.........
开发者ID:nrrrdcore,项目名称:newthing,代码行数:101,代码来源:TarInputStream.cs

示例4: GetNextEntry

        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;
        }
开发者ID:NoobSkie,项目名称:taobao-shop-helper,代码行数:96,代码来源:TarInputStream.cs


注:本文中的ICSharpCode.SharpZipLib.Tar.TarHeader.ParseBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。