GetAsciiBytes() public static method

Add a string to a buffer as a collection of ascii bytes.
public static GetAsciiBytes ( string toAdd, int nameOffset, byte buffer, int bufferOffset, int length ) : int
toAdd string The string to add
nameOffset int The offset of the first character to add.
buffer byte The buffer to add to.
bufferOffset int The offset to start adding at.
length int The number of ascii characters to add.
return int
Example #1
0
 public void PutNextEntry(TarEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     if (entry.TarHeader.Name.Length > 100)
     {
         TarHeader tarHeader = new TarHeader();
         tarHeader.TypeFlag  = 76;
         tarHeader.Name     += "././@LongLink";
         tarHeader.Mode      = 420;
         tarHeader.UserId    = entry.UserId;
         tarHeader.GroupId   = entry.GroupId;
         tarHeader.GroupName = entry.GroupName;
         tarHeader.UserName  = entry.UserName;
         tarHeader.LinkName  = string.Empty;
         tarHeader.Size      = (long)(entry.TarHeader.Name.Length + 1);
         tarHeader.WriteHeader(this.blockBuffer);
         this.buffer.WriteBlock(this.blockBuffer);
         int i = 0;
         while (i < entry.TarHeader.Name.Length + 1)
         {
             Array.Clear(this.blockBuffer, 0, this.blockBuffer.Length);
             TarHeader.GetAsciiBytes(entry.TarHeader.Name, i, this.blockBuffer, 0, 512);
             i += 512;
             this.buffer.WriteBlock(this.blockBuffer);
         }
     }
     entry.WriteEntryHeader(this.blockBuffer);
     this.buffer.WriteBlock(this.blockBuffer);
     this.currBytes = 0L;
     this.currSize  = ((!entry.IsDirectory) ? entry.Size : 0L);
 }
Example #2
0
 public void PutNextEntry(TarEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     if (entry.TarHeader.Name.Length >= 100)
     {
         TarHeader header = new TarHeader {
             TypeFlag = 0x4c
         };
         header.Name      = header.Name + "././@LongLink";
         header.UserId    = 0;
         header.GroupId   = 0;
         header.GroupName = "";
         header.UserName  = "";
         header.LinkName  = "";
         header.Size      = entry.TarHeader.Name.Length + 1;
         header.WriteHeader(this.blockBuffer);
         this.buffer.WriteBlock(this.blockBuffer);
         int nameOffset = 0;
         while (nameOffset < entry.TarHeader.Name.Length)
         {
             Array.Clear(this.blockBuffer, 0, this.blockBuffer.Length);
             TarHeader.GetAsciiBytes(entry.TarHeader.Name, nameOffset, this.blockBuffer, 0, 0x200);
             nameOffset += 0x200;
             this.buffer.WriteBlock(this.blockBuffer);
         }
     }
     entry.WriteEntryHeader(this.blockBuffer);
     this.buffer.WriteBlock(this.blockBuffer);
     this.currBytes = 0L;
     this.currSize  = entry.IsDirectory ? 0L : entry.Size;
 }
Example #3
0
 public void PutNextEntry(TarEntry entry)
 {
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     if (entry.TarHeader.Name.Length >= 100)
     {
         TarHeader tarHeader = new TarHeader();
         tarHeader.TypeFlag  = 76;
         tarHeader.Name     += "././@LongLink";
         tarHeader.UserId    = 0;
         tarHeader.GroupId   = 0;
         tarHeader.GroupName = "";
         tarHeader.UserName  = "";
         tarHeader.LinkName  = "";
         tarHeader.Size      = entry.TarHeader.Name.Length;
         tarHeader.WriteHeader(blockBuffer);
         buffer.WriteBlock(blockBuffer);
         int num = 0;
         while (num < entry.TarHeader.Name.Length)
         {
             Array.Clear(blockBuffer, 0, blockBuffer.Length);
             TarHeader.GetAsciiBytes(entry.TarHeader.Name, num, blockBuffer, 0, 512);
             num += 512;
             buffer.WriteBlock(blockBuffer);
         }
     }
     entry.WriteEntryHeader(blockBuffer);
     buffer.WriteBlock(blockBuffer);
     currBytes = 0L;
     currSize  = (entry.IsDirectory ? 0 : entry.Size);
 }
 public void PutNextEntry(TarEntry entry)
 {
     //IL_0008: Unknown result type (might be due to invalid IL or missing references)
     if (entry == null)
     {
         throw new ArgumentNullException("entry");
     }
     if (entry.TarHeader.Name.get_Length() >= 100)
     {
         TarHeader tarHeader = new TarHeader();
         tarHeader.TypeFlag  = 76;
         tarHeader.Name     += "././@LongLink";
         tarHeader.UserId    = 0;
         tarHeader.GroupId   = 0;
         tarHeader.GroupName = "";
         tarHeader.UserName  = "";
         tarHeader.LinkName  = "";
         tarHeader.Size      = entry.TarHeader.Name.get_Length();
         tarHeader.WriteHeader(blockBuffer);
         buffer.WriteBlock(blockBuffer);
         int num = 0;
         while (num < entry.TarHeader.Name.get_Length())
         {
             global::System.Array.Clear((global::System.Array)blockBuffer, 0, blockBuffer.Length);
             TarHeader.GetAsciiBytes(entry.TarHeader.Name, num, blockBuffer, 0, 512);
             num += 512;
             buffer.WriteBlock(blockBuffer);
         }
     }
     entry.WriteEntryHeader(blockBuffer);
     buffer.WriteBlock(blockBuffer);
     currBytes = 0L;
     currSize  = (entry.IsDirectory ? 0 : entry.Size);
 }
Example #5
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 == null)
            {
                throw new ArgumentNullException(nameof(entry));
            }

            var namelen = nameEncoding != null?nameEncoding.GetByteCount(entry.TarHeader.Name) : entry.TarHeader.Name.Length;

            if (namelen > 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      = namelen + 1;             // Plus one to avoid dropping last char

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

                int nameCharIndex = 0;

                while (nameCharIndex < namelen + 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, nameEncoding);                     // This func handles OK the extra char out of string length
                    nameCharIndex += TarBuffer.BlockSize;
                    buffer.WriteBlock(blockBuffer);
                }
            }

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

            currBytes = 0;

            currSize = entry.IsDirectory ? 0 : entry.Size;
        }
Example #6
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 == null)
            {
                throw new ArgumentNullException("entry");
            }

            if (entry.TarHeader.Name.Length >= TarHeader.NAMELEN)
            {
                TarHeader longHeader = new TarHeader();
                longHeader.TypeFlag  = TarHeader.LF_GNU_LONGNAME;
                longHeader.Name      = longHeader.Name + "././@LongLink";
                longHeader.UserId    = 0;
                longHeader.GroupId   = 0;
                longHeader.GroupName = "";
                longHeader.UserName  = "";
                longHeader.LinkName  = "";

                longHeader.Size = entry.TarHeader.Name.Length;

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

                int nameCharIndex = 0;

                while (nameCharIndex < entry.TarHeader.Name.Length)
                {
                    Array.Clear(blockBuffer, 0, blockBuffer.Length);
                    TarHeader.GetAsciiBytes(entry.TarHeader.Name, nameCharIndex, this.blockBuffer, 0, TarBuffer.BlockSize);
                    nameCharIndex += TarBuffer.BlockSize;
                    buffer.WriteBlock(blockBuffer);
                }
            }

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

            currBytes = 0;

            currSize = entry.IsDirectory ? 0 : entry.Size;
        }
Example #7
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 #8
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 == 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)
                {
                    Array.Clear(blockBuffer, 0, blockBuffer.Length);
                    TarHeader.GetAsciiBytes(entry.TarHeader.Name, nameCharIndex, this.blockBuffer, 0, TarBuffer.BlockSize);
                    nameCharIndex += TarBuffer.BlockSize;
                    buffer.WriteBlock(blockBuffer);
                }
            }

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

            currBytes = 0;

            currSize = entry.IsDirectory ? 0 : entry.Size;
        }
Example #9
0
 public void PutNextEntry(TarEntry entry)
 {
     if (entry.TarHeader.Name.Length >= TarHeader.NAMELEN)
     {
         TarHeader header = new TarHeader();
         new TarHeader {
             TypeFlag = 0x4c, Name = header.Name + "././@LongLink", UserId = 0, GroupId = 0, GroupName = "", UserName = "", LinkName = "", Size = entry.TarHeader.Name.Length
         }.WriteHeader(this.blockBuf);
         this.buffer.WriteBlock(this.blockBuf);
         int nameOffset = 0;
         while (nameOffset < entry.TarHeader.Name.Length)
         {
             Array.Clear(this.blockBuf, 0, this.blockBuf.Length);
             TarHeader.GetAsciiBytes(entry.TarHeader.Name, nameOffset, this.blockBuf, 0, 0x200);
             nameOffset += 0x200;
             this.buffer.WriteBlock(this.blockBuf);
         }
     }
     entry.WriteEntryHeader(this.blockBuf);
     this.buffer.WriteBlock(this.blockBuf);
     this.currBytes = 0L;
     this.currSize  = entry.IsDirectory ? 0L : entry.Size;
 }