GetNameBytes() public static method

Add an entry name to the buffer
public static GetNameBytes ( StringBuilder name, byte buffer, int offset, int length ) : int
name StringBuilder /// The name to add ///
buffer byte /// The buffer to add to ///
offset int /// The offset into the buffer from which to start adding ///
length int /// The number of header bytes to add ///
return int
Example #1
0
        /// <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.TarHeader.name.Length > TarHeader.NAMELEN)
            {
                TarHeader longHeader = new TarHeader();
                longHeader.typeFlag = TarHeader.LF_GNU_LONGNAME;
                longHeader.name.Append("././@LongLink");
                longHeader.userId           = 0;
                longHeader.groupId          = 0;
                longHeader.groupName.Length = 0;
                longHeader.userName.Length  = 0;
                longHeader.linkName.Length  = 0;

                longHeader.size = entry.TarHeader.name.Length;

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

                int nameCharIndex = 0;

                while (nameCharIndex < entry.TarHeader.name.Length)
                {
                    TarHeader.GetNameBytes(entry.TarHeader.name, nameCharIndex, this.blockBuf, 0, TarBuffer.BlockSize);
                    nameCharIndex += TarBuffer.BlockSize;
                    this.buffer.WriteBlock(this.blockBuf);
                }
            }

            entry.WriteEntryHeader(this.blockBuf);
            this.buffer.WriteBlock(this.blockBuf);

            this.currBytes = 0;

            this.currSize = entry.IsDirectory ? 0 : entry.Size;
        }
Example #2
0
 public static int GetNameBytes(string name, byte[] buffer, int offset, int length)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     return(TarHeader.GetNameBytes(name, 0, buffer, offset, length));
 }
Example #3
0
 public static int GetNameBytes(StringBuilder name, int nameOffset, byte[] buffer, int bufferOffset, int length)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     return(TarHeader.GetNameBytes(name.ToString(), nameOffset, buffer, bufferOffset, length));
 }
Example #4
0
        public void WriteHeader(byte[] outBuffer)
        {
            if (outBuffer == null)
            {
                throw new ArgumentNullException("outBuffer");
            }
            int i = 0;

            i = TarHeader.GetNameBytes(this.Name, outBuffer, i, 100);
            i = TarHeader.GetOctalBytes((long)this.mode, outBuffer, i, 8);
            i = TarHeader.GetOctalBytes((long)this.UserId, outBuffer, i, 8);
            i = TarHeader.GetOctalBytes((long)this.GroupId, outBuffer, i, 8);
            long value = this.Size;

            i = TarHeader.GetLongOctalBytes(value, outBuffer, i, 12);
            i = TarHeader.GetLongOctalBytes((long)TarHeader.GetCTime(this.ModTime), outBuffer, i, 12);
            int offset = i;

            for (int j = 0; j < 8; j++)
            {
                outBuffer[i++] = 32;
            }
            outBuffer[i++] = this.TypeFlag;
            i = TarHeader.GetNameBytes(this.LinkName, outBuffer, i, 100);
            i = TarHeader.GetAsciiBytes(this.Magic, 0, outBuffer, i, 6);
            i = TarHeader.GetNameBytes(this.Version, outBuffer, i, 2);
            i = TarHeader.GetNameBytes(this.UserName, outBuffer, i, 32);
            i = TarHeader.GetNameBytes(this.GroupName, outBuffer, i, 32);
            if (this.TypeFlag == 51 || this.TypeFlag == 52)
            {
                i = TarHeader.GetOctalBytes((long)this.DevMajor, outBuffer, i, 8);
                i = TarHeader.GetOctalBytes((long)this.DevMinor, outBuffer, i, 8);
            }
            while (i < outBuffer.Length)
            {
                outBuffer[i++] = 0;
            }
            this.checksum = TarHeader.ComputeCheckSum(outBuffer);
            TarHeader.GetCheckSumOctalBytes((long)this.checksum, outBuffer, offset, 8);
            this.isChecksumValid = true;
        }
Example #5
0
        /// <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);
        }
Example #6
0
 public static void AdjustEntryName(byte[] buffer, string newName)
 {
     TarHeader.GetNameBytes(newName, buffer, 0, 100);
 }
Example #7
0
        /// <summary>
        /// Convenience method that will modify an entry's name directly
        /// in place in an entry header buffer byte array.
        /// </summary>
        /// <param name="buffer">
        /// The buffer containing the entry header to modify.
        /// </param>
        /// <param name="newName">
        /// The new name to place into the header buffer.
        /// </param>
        static public void AdjustEntryName(byte[] buffer, string newName)
        {
            int offset = 0;

            TarHeader.GetNameBytes(newName, buffer, offset, TarHeader.NAMELEN);
        }
Example #8
0
 /// <summary>
 /// Convenience method that will modify an entry's name directly
 /// in place in an entry header buffer byte array.
 /// </summary>
 /// <param name="buffer">
 /// The buffer containing the entry header to modify.
 /// </param>
 /// <param name="newName">
 /// The new name to place into the header buffer.
 /// </param>
 /// <param name="nameEncoding">
 /// The <see cref="Encoding"/> used for the Name fields, or null for ASCII only
 /// </param>
 static public void AdjustEntryName(byte[] buffer, string newName, Encoding nameEncoding)
 {
     TarHeader.GetNameBytes(newName, buffer, 0, TarHeader.NAMELEN, nameEncoding);
 }