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


C# Tar.TarHeader类代码示例

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


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

示例1: WriteObjectToTar

		private void WriteObjectToTar (TarOutputStream  tar_out,
					       FileSystemObject fso,
					       EventTracker     tracker)
		{
			MemoryStream memory = null;

			TarHeader header;
			header = new TarHeader ();

			StringBuilder name_builder;
			name_builder = new StringBuilder (fso.FullName);
			name_builder.Remove (0, this.FullName.Length+1);
			header.Name = name_builder.ToString ();

			header.ModTime = fso.Timestamp;
			if (fso is DirectoryObject) {
				header.Mode = 511; // 0777
				header.TypeFlag = TarHeader.LF_DIR;
				header.Size = 0;
			} else {
				header.Mode = 438; // 0666
				header.TypeFlag = TarHeader.LF_NORMAL;
				memory = new MemoryStream ();
				((FileObject) fso).AddToStream (memory, tracker);
				header.Size = memory.Length;
			}

			TarEntry entry;
			entry = new TarEntry (header);

			tar_out.PutNextEntry (entry);
			if (memory != null) {
				tar_out.Write (memory.ToArray (), 0, (int) memory.Length);
				memory.Close ();
			}
			tar_out.CloseEntry ();

			// If this is a directory, write out the children
			if (fso is DirectoryObject)
				foreach (FileSystemObject child in fso.Children)
					WriteObjectToTar (tar_out, child, tracker);
		}
开发者ID:ArsenShnurkov,项目名称:beagle-1,代码行数:42,代码来源:TarFileObject.cs

示例2: TarEntry

        /// <summary>
        /// Construct a TarEntry using the <paramref name="header">header</paramref> provided
        /// </summary>
        /// <param name="header">Header details for entry</param>
        public TarEntry(TarHeader header)
        {
            if (header == null) {
                throw new ArgumentNullException("TarHeader");
            }

            this.header = (TarHeader)header.Clone();
        }
开发者ID:,项目名称:,代码行数:12,代码来源:

示例3: GetFileTarHeader

		/// <summary>
		/// Fill in a TarHeader with information from a File.
		/// </summary>
		/// <param name="hdr">
		/// The TarHeader to fill in.
		/// </param>
		/// <param name="file">
		/// The file from which to get the header information.
		/// </param>
		public void GetFileTarHeader(TarHeader hdr, string file)
		{
			this.file = file;

			// bugfix from torhovl from #D forum:
			string name = file;

         // -jr- 23-Jan-2004 HAK HAK HAK, GnuTar allows device names in path where the name is not local to the current directory
         if (Environment.CurrentDirectory == Path.GetDirectoryName(name))
         {
            name = Path.GetFileName(name);
         }
/*			
         if (Path.DirectorySeparatorChar == '\\') 
			{  // check if the OS is Windows
				// Strip off drive letters!
				if (name.Length > 2) 
				{
					char ch1 = name[0];
					char ch2 = name[1];
					
					if (ch2 == ':' && Char.IsLetter(ch1)) 
					{
						name = name.Substring(2);
					}
				}
			}
*/
			
			name = name.Replace(Path.DirectorySeparatorChar, '/').ToLower();

			// No absolute pathnames
			// Windows (and Posix?) paths can start with UNC style "\\NetworkDrive\",
			// so we loop on starting /'s.
			while (name.StartsWith("/")) {
				name = name.Substring(1);
			}

			hdr.linkName = new StringBuilder(String.Empty);
			hdr.name     = new StringBuilder(name);
			
			if (Directory.Exists(file)) {
				hdr.mode     = 1003; // 01753 -jr- no octal constants!! 040755; // Magic number for security access for a UNIX filesystem
				hdr.typeFlag = TarHeader.LF_DIR;
				if (hdr.name.Length == 0 || hdr.name[hdr.name.Length - 1] != '/') {
					hdr.name.Append("/");
				}
				
				hdr.size     = 0;
			} else {
				hdr.mode     = 33216; // 0100700 -jr-  // 0100644; // Magic number for security access for a UNIX filesystem
				hdr.typeFlag = TarHeader.LF_NORMAL;
				hdr.size     = new FileInfo(file.Replace('/', Path.DirectorySeparatorChar)).Length;
			}
			
			// UNDONE When File lets us get the userName, use it!
         hdr.modTime = System.IO.File.GetLastWriteTimeUtc(file.Replace('/', Path.DirectorySeparatorChar)); // -jr- Unix times are in UTC
         hdr.checkSum = 0;
			hdr.devMajor = 0;
			hdr.devMinor = 0;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:70,代码来源:TarEntry.cs

示例4: Initialize

		/// <summary>
		/// Initialization code common to all pseudo constructors.
		/// </summary>
		void Initialize()
		{
			this.file   = null;
			this.header = new TarHeader();
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:TarEntry.cs

示例5: TarEntry

 public TarEntry(TarHeader header)
 {
    file = null;
    this.header = header;
 }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:5,代码来源:TarEntry.cs

示例6: PutNextEntry

        /// <summary>
        /// Put an entry on the output stream. This writes the entry's
        /// header and positions the output stream for writing
        /// the contents of the entry. Once this method is called, the
        /// stream is ready for calls to write() to write the entry's
        /// contents. Once the contents are written, closeEntry()
        /// <B>MUST</B> be called to ensure that all buffered data
        /// is completely written to the output stream.
        /// </summary>
        /// <param name="entry">
        /// The TarEntry to be written to the archive.
        /// </param>
        public void PutNextEntry(TarEntry entry)
        {
            if (entry == null) {
                throw new ArgumentNullException(nameof(entry));
            }

            if (entry.TarHeader.Name.Length > TarHeader.NAMELEN) {
                var longHeader = new TarHeader();
                longHeader.TypeFlag = TarHeader.LF_GNU_LONGNAME;
                longHeader.Name = longHeader.Name + "././@LongLink";
                longHeader.Mode = 420;//644 by default
                longHeader.UserId = entry.UserId;
                longHeader.GroupId = entry.GroupId;
                longHeader.GroupName = entry.GroupName;
                longHeader.UserName = entry.UserName;
                longHeader.LinkName = "";
                longHeader.Size = entry.TarHeader.Name.Length + 1;  // Plus one to avoid dropping last char

                longHeader.WriteHeader(blockBuffer);
                buffer.WriteBlock(blockBuffer);  // Add special long filename header block

                int nameCharIndex = 0;

                while (nameCharIndex < entry.TarHeader.Name.Length + 1 /* we've allocated one for the null char, now we must make sure it gets written out */) {
                    Array.Clear(blockBuffer, 0, blockBuffer.Length);
                    TarHeader.GetAsciiBytes(entry.TarHeader.Name, nameCharIndex, this.blockBuffer, 0, TarBuffer.BlockSize); // This func handles OK the extra char out of string length
                    nameCharIndex += TarBuffer.BlockSize;
                    buffer.WriteBlock(blockBuffer);
                }
            }

            entry.WriteEntryHeader(blockBuffer);
            buffer.WriteBlock(blockBuffer);

            currBytes = 0;

            currSize = entry.IsDirectory ? 0 : entry.Size;
        }
开发者ID:icsharpcode,项目名称:SharpZipLib,代码行数:50,代码来源:TarOutputStream.cs

示例7: TarEntry

		/// <summary>
		/// Initialise a default instance of <see cref="TarEntry"/>.
		/// </summary>
		private TarEntry()
		{
			header = new TarHeader();
		}
开发者ID:lPinchol,项目名称:Reign-Unity-Plugin,代码行数:7,代码来源:TarEntry.cs

示例8: Clone

		/// <summary>
		/// TarHeaders can be cloned.
		/// </summary>
		public object Clone()
		{
			TarHeader hdr = new TarHeader();
			
			hdr.name      = (this.name == null) ? null : new StringBuilder(this.name.ToString());
			hdr.mode      = this.mode;
			hdr.userId    = this.userId;
			hdr.groupId   = this.groupId;
			hdr.size      = this.size;
			hdr.modTime   = this.modTime;
			hdr.checkSum  = this.checkSum;
			hdr.typeFlag  = this.typeFlag;
			hdr.linkName  = (this.linkName == null)  ? null : new StringBuilder(this.linkName.ToString());
			hdr.magic     = (this.magic == null)     ? null : new StringBuilder(this.magic.ToString());
         hdr.version   = (this.version == null)   ? null : new StringBuilder(this.version.ToString());
			hdr.userName  = (this.userName == null)  ? null : new StringBuilder(this.userName.ToString());
			hdr.groupName = (this.groupName == null) ? null : new StringBuilder(this.groupName.ToString());
			hdr.devMajor  = this.devMajor;
			hdr.devMinor  = this.devMinor;
			
			return hdr;
		}
开发者ID:jack-pappas,项目名称:mono,代码行数:25,代码来源:TarHeader.cs

示例9: 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

示例10: GetFileTarHeader

        public void GetFileTarHeader(TarHeader header, string file)
        {
            if ( header == null ) {
                throw new ArgumentNullException("header");
            }

            if ( file == null ) {
                throw new ArgumentNullException("file");
            }

            this.file = file;

            string name = file;

            #if !NETCF_1_0 && !NETCF_2_0

            if (name.IndexOf(Environment.CurrentDirectory) == 0) {
                name = name.Substring(Environment.CurrentDirectory.Length);
            }
            #endif

            name = name.Replace(Path.DirectorySeparatorChar, '/');

            while (name.StartsWith("/")) {
                name = name.Substring(1);
            }

            header.LinkName = String.Empty;
            header.Name     = name;

            if (Directory.Exists(file)) {
                header.Mode     = 1003;
                header.TypeFlag = TarHeader.LF_DIR;
                if ( (header.Name.Length == 0) || header.Name[header.Name.Length - 1] != '/') {
                    header.Name = header.Name + "/";
                }

                header.Size     = 0;
            } else {
                header.Mode     = 33216;
                header.TypeFlag = TarHeader.LF_NORMAL;
                header.Size     = new FileInfo(file.Replace('/', Path.DirectorySeparatorChar)).Length;
            }

            header.ModTime = System.IO.File.GetLastWriteTime(file.Replace('/', Path.DirectorySeparatorChar)).ToUniversalTime();
            header.DevMajor = 0;
            header.DevMinor = 0;
        }
开发者ID:NoobSkie,项目名称:taobao-shop-helper,代码行数:48,代码来源:TarEntry.cs

示例11: Clone

		/// <summary>
		/// Clone a TAR header.
		/// </summary>
		public object Clone()
		{
			TarHeader hdr = new TarHeader();
			
			hdr.Name      = Name;
			hdr.Mode      = this.Mode;
			hdr.UserId    = this.UserId;
			hdr.GroupId   = this.GroupId;
			hdr.Size      = this.Size;
			hdr.ModTime   = this.ModTime;
			hdr.TypeFlag  = this.TypeFlag;
			hdr.LinkName  = this.LinkName;
			hdr.Magic     = this.Magic;
			hdr.Version   = this.Version;
			hdr.UserName  = this.UserName;
			hdr.GroupName = this.GroupName;
			hdr.DevMajor  = this.DevMajor;
			hdr.DevMinor  = this.DevMinor;
			
			return hdr;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:24,代码来源:TarHeader.cs

示例12: GetFileTarHeader

		/// <summary>
		/// Fill in a TarHeader with information from a File.
		/// </summary>
		/// <param name="header">
		/// The TarHeader to fill in.
		/// </param>
		/// <param name="file">
		/// The file from which to get the header information.
		/// </param>
		public void GetFileTarHeader(TarHeader header, string file)
		{
			if ( header == null ) {
				throw new ArgumentNullException("header");
			}

			if ( file == null ) {
				throw new ArgumentNullException("file");
			}

			this.file = file;

            header.LinkName = String.Empty;
            /// <remarks>
            /// Needed to remove directory tree for ODIN sanity
            /// header.Name = name;
            /// </remarks>
            header.Name = Path.GetFileName(file);
			
			if (Directory.Exists(file)) {
				header.Mode     = 1003; // Magic number for security access for a UNIX filesystem
				header.TypeFlag = TarHeader.LF_DIR;
				if ( (header.Name.Length == 0) || header.Name[header.Name.Length - 1] != '/') {
					header.Name = header.Name + "/";
				}
				
				header.Size     = 0;
			} else {
				header.Mode     = 33216; // Magic number for security access for a UNIX filesystem
				header.TypeFlag = TarHeader.LF_NORMAL;
				header.Size     = new FileInfo(file.Replace('/', Path.DirectorySeparatorChar)).Length;
			}

			header.ModTime = System.IO.File.GetLastWriteTime(file.Replace('/', Path.DirectorySeparatorChar)).ToUniversalTime();
			header.DevMajor = 0;
			header.DevMinor = 0;
		}
开发者ID:pkdevboxy,项目名称:guitar,代码行数:46,代码来源:TarEntry.cs

示例13: 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

示例14: NameTarHeader

        /// <summary>
        /// Fill in a TarHeader given only the entry's name.
        /// </summary>
        /// <param name="hdr">
        /// The TarHeader to fill in.
        /// </param>
        /// <param name="name">
        /// The tar entry name.
        /// </param>
        public void NameTarHeader(TarHeader hdr, string name)
        {
            bool isDir = name.EndsWith("/");

            hdr.checkSum = 0;

            hdr.name = new StringBuilder(name);
            hdr.mode = isDir ? 1003 : 33216;
            hdr.userId   = 0;
            hdr.groupId  = 0;
            hdr.size     = 0;
            hdr.checkSum = 0;

            hdr.modTime  = DateTime.UtcNow;

            hdr.typeFlag = isDir ? TarHeader.LF_DIR : TarHeader.LF_NORMAL;

            hdr.linkName  = new StringBuilder(String.Empty);
            hdr.userName  = new StringBuilder(String.Empty);
            hdr.groupName = new StringBuilder(String.Empty);

            hdr.devMajor = 0;
            hdr.devMinor = 0;
        }
开发者ID:foresightbrand,项目名称:brandqq,代码行数:33,代码来源:TarEntry.cs

示例15: NameTarHeader

		/// <summary>
		/// Fill in a TarHeader given only the entry's name.
		/// </summary>
		/// <param name="hdr">
		/// The TarHeader to fill in.
		/// </param>
		/// <param name="name">
		/// The tar entry name.
		/// </param>
		public void NameTarHeader(TarHeader hdr, string name)
		{
			bool isDir = name.EndsWith("/");   // -jr- this is true for BSD tar but not all others I think?
			
			hdr.checkSum = 0;
			
			hdr.name = new StringBuilder(name);
//			hdr.mode = isDir ? 040755 : 0100644; // TODO : I think I've seen these magics before ...
         hdr.mode = isDir ? 1003 : 33216;
         hdr.userId   = 0;
			hdr.groupId  = 0;
			hdr.size     = 0;
			hdr.checkSum = 0;
			
         hdr.modTime  = DateTime.UtcNow;        // -jr- 24-Jan-2004 Unix times are in utc!
//			hdr.modTime  = DateTime.Now;   // (new java.util.Date()).getTime() / 1000;
			
			hdr.typeFlag = isDir ? TarHeader.LF_DIR : TarHeader.LF_NORMAL;
			
			hdr.linkName  = new StringBuilder(String.Empty);
			hdr.userName  = new StringBuilder(String.Empty);
			hdr.groupName = new StringBuilder(String.Empty);
			
			hdr.devMajor = 0;
			hdr.devMinor = 0;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:35,代码来源:TarEntry.cs


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