MakeCheckSum() статический приватный Метод

Make a checksum for a tar entry ignoring the checksum contents.
static private MakeCheckSum ( byte buffer ) : int
buffer byte The tar entry's header buffer.
Результат int
Пример #1
0
        /// <summary>
        /// Parse TarHeader information from a header buffer.
        /// </summary>
        /// <param name = "header">
        /// The tar entry header buffer to get information from.
        /// </param>
        public void ParseBuffer(byte[] header)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            int offset = 0;

            name    = TarHeader.ParseName(header, offset, TarHeader.NAMELEN).ToString();
            offset += TarHeader.NAMELEN;

            mode    = (int)TarHeader.ParseOctal(header, offset, TarHeader.MODELEN);
            offset += TarHeader.MODELEN;

            UserId  = (int)TarHeader.ParseOctal(header, offset, TarHeader.UIDLEN);
            offset += TarHeader.UIDLEN;

            GroupId = (int)TarHeader.ParseOctal(header, offset, TarHeader.GIDLEN);
            offset += TarHeader.GIDLEN;

            Size    = TarHeader.ParseOctal(header, offset, TarHeader.SIZELEN);
            offset += TarHeader.SIZELEN;

            ModTime = GetDateTimeFromCTime(TarHeader.ParseOctal(header, offset, TarHeader.MODTIMELEN));
            offset += TarHeader.MODTIMELEN;

            checksum = (int)TarHeader.ParseOctal(header, offset, TarHeader.CHKSUMLEN);
            offset  += TarHeader.CHKSUMLEN;

            TypeFlag = header[offset++];

            LinkName = TarHeader.ParseName(header, offset, TarHeader.NAMELEN).ToString();
            offset  += TarHeader.NAMELEN;

            Magic   = TarHeader.ParseName(header, offset, TarHeader.MAGICLEN).ToString();
            offset += TarHeader.MAGICLEN;

            Version = TarHeader.ParseName(header, offset, TarHeader.VERSIONLEN).ToString();
            offset += TarHeader.VERSIONLEN;

            UserName = TarHeader.ParseName(header, offset, TarHeader.UNAMELEN).ToString();
            offset  += TarHeader.UNAMELEN;

            GroupName = TarHeader.ParseName(header, offset, TarHeader.GNAMELEN).ToString();
            offset   += TarHeader.GNAMELEN;

            DevMajor = (int)TarHeader.ParseOctal(header, offset, TarHeader.DEVLEN);
            offset  += TarHeader.DEVLEN;

            DevMinor = (int)TarHeader.ParseOctal(header, offset, TarHeader.DEVLEN);

            // Fields past this point not currently parsed or used...

            isChecksumValid = Checksum == TarHeader.MakeCheckSum(header);
        }
Пример #2
0
        public void ParseBuffer(byte[] header)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }
            int num = 0;

            this.name     = TarHeader.ParseName(header, num, 100).ToString();
            num          += 100;
            this.mode     = (int)TarHeader.ParseOctal(header, num, 8);
            num          += 8;
            this.UserId   = (int)TarHeader.ParseOctal(header, num, 8);
            num          += 8;
            this.GroupId  = (int)TarHeader.ParseOctal(header, num, 8);
            num          += 8;
            this.Size     = TarHeader.ParseBinaryOrOctal(header, num, 12);
            num          += 12;
            this.ModTime  = TarHeader.GetDateTimeFromCTime(TarHeader.ParseOctal(header, num, 12));
            num          += 12;
            this.checksum = (int)TarHeader.ParseOctal(header, num, 8);
            num          += 8;
            this.TypeFlag = header[num++];
            this.LinkName = TarHeader.ParseName(header, num, 100).ToString();
            num          += 100;
            this.Magic    = TarHeader.ParseName(header, num, 6).ToString();
            num          += 6;
            if (this.Magic == "ustar")
            {
                this.Version   = TarHeader.ParseName(header, num, 2).ToString();
                num           += 2;
                this.UserName  = TarHeader.ParseName(header, num, 32).ToString();
                num           += 32;
                this.GroupName = TarHeader.ParseName(header, num, 32).ToString();
                num           += 32;
                this.DevMajor  = (int)TarHeader.ParseOctal(header, num, 8);
                num           += 8;
                this.DevMinor  = (int)TarHeader.ParseOctal(header, num, 8);
                num           += 8;
                string text = TarHeader.ParseName(header, num, 155).ToString();
                if (!string.IsNullOrEmpty(text))
                {
                    this.Name = text + '/' + this.Name;
                }
            }
            this.isChecksumValid = (this.Checksum == TarHeader.MakeCheckSum(header));
        }
Пример #3
0
        /// <summary>
        /// Parse TarHeader information from a header buffer.
        /// </summary>
        /// <param name = "header">
        /// The tar entry header buffer to get information from.
        /// </param>
        public void ParseBuffer(byte[] header)
        {
            if (header == null)
            {
                throw new ArgumentNullException(nameof(header));
            }

            int offset = 0;

            name    = ParseName(header, offset, NAMELEN).ToString();
            offset += NAMELEN;

            mode    = (int)ParseOctal(header, offset, MODELEN);
            offset += MODELEN;

            UserId  = (int)ParseOctal(header, offset, UIDLEN);
            offset += UIDLEN;

            GroupId = (int)ParseOctal(header, offset, GIDLEN);
            offset += GIDLEN;

            Size    = ParseBinaryOrOctal(header, offset, SIZELEN);
            offset += SIZELEN;

            ModTime = GetDateTimeFromCTime(ParseOctal(header, offset, MODTIMELEN));
            offset += MODTIMELEN;

            checksum = (int)ParseOctal(header, offset, CHKSUMLEN);
            offset  += CHKSUMLEN;

            TypeFlag = header[offset++];

            LinkName = ParseName(header, offset, NAMELEN).ToString();
            offset  += NAMELEN;

            Magic   = ParseName(header, offset, MAGICLEN).ToString();
            offset += MAGICLEN;

            if (Magic == "ustar")
            {
                Version = ParseName(header, offset, VERSIONLEN).ToString();
                offset += VERSIONLEN;

                UserName = ParseName(header, offset, UNAMELEN).ToString();
                offset  += UNAMELEN;

                GroupName = ParseName(header, offset, GNAMELEN).ToString();
                offset   += GNAMELEN;

                DevMajor = (int)ParseOctal(header, offset, DEVLEN);
                offset  += DEVLEN;

                DevMinor = (int)ParseOctal(header, offset, DEVLEN);
                offset  += DEVLEN;

                string prefix = ParseName(header, offset, PREFIXLEN).ToString();
                if (!string.IsNullOrEmpty(prefix))
                {
                    Name = prefix + '/' + Name;
                }
            }

            isChecksumValid = Checksum == TarHeader.MakeCheckSum(header);
        }