/// <summary>
 /// Add the checksum integer to header buffer.
 /// </summary>
 /// <param name="val">The value.</param>
 /// <param name="buf">The header buffer to set the checksum for</param>
 /// <param name="offset">The offset into the buffer for the checksum</param>
 /// <param name="length">The number of header bytes to update.
 /// It's formatted differently from the other fields: it has 6 digits, a
 /// null, then a space -- rather than digits, a space, then a null.
 /// The final space is already there, from checksumming</param>
 /// <returns>The modified buffer offset</returns>
 private static int GetCheckSumOctalBytes(long val, byte[] buf, int offset, int length)
 {
     TarHeader.GetOctalBytes(val, buf, offset, length - 1);
     return(offset + length);
 }
 /// <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)
 {
     file        = null;
     this.header = header;
 }
        /// <summary>
        /// Convenience method that will modify an entry's name directly
        /// in place in an entry header buffer byte array.
        /// </summary>
        /// <param name="outbuf">The buffer containing the entry header to modify.</param>
        /// <param name="newName">The new name to place into the header buffer.</param>
        public void AdjustEntryName(byte[] outbuf, string newName)
        {
            int offset = 0;

            TarHeader.GetNameBytes(newName, outbuf, offset, TarHeader.NAMELEN);
        }
        /// <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;

#if !COMPACT_FRAMEWORK
            // 23-Jan-2004 GnuTar allows device names in path where the name is not local to the current directory
            if (name.IndexOf(Environment.CurrentDirectory) == 0)
            {
                name = name.Substring(Environment.CurrentDirectory.Length);
            }
#endif

/*
 *                      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, '/');

            // 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 = String.Empty;
            hdr.Name     = name;

            if (Directory.Exists(file))
            {
                hdr.Mode     = 1003;                 // 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 = hdr.Name + "/";
                }

                hdr.Size = 0;
            }
            else
            {
                hdr.Mode     = 33216;                 // Magic number for security access for a UNIX filesystem
                hdr.TypeFlag = TarHeader.LF_NORMAL;
                hdr.Size     = new FileInfo(file.Replace('/', Path.DirectorySeparatorChar)).Length;
            }

            hdr.ModTime  = System.IO.File.GetLastWriteTime(file.Replace('/', Path.DirectorySeparatorChar)).ToUniversalTime();
            hdr.DevMajor = 0;
            hdr.DevMinor = 0;
        }
 /// <summary>
 /// Initialization code common to all pseudo constructors.
 /// </summary>
 void Initialize()
 {
     this.file   = null;
     this.header = new TarHeader();
 }