public bool TryPutString(string str, TarHeader.HeaderField field)
        {
            if (str == null)
            {
                PutNul(field);
                return(true);
            }

            if (TarCommon.IsASCII(str))
            {
                if (str.Length <= field.Length)
                {
                    for (int i = 0; i < str.Length; i++)
                    {
                        this[field.Offset + i] = (byte)str[i];
                    }

                    PutNul(field.Offset + str.Length, field.Length - str.Length);
                    return(true);
                }
            }

            if (field.PaxAttribute != null && PaxAttributes != null)
            {
                PaxAttributes[field.PaxAttribute] = str;
            }

            PutNul(field);
            return(false);
        }
Example #2
0
        // Tries to split a path at a '/' character so that the two pieces will fit into
        // the prefix and name fields.
        private static bool TrySplitPath(string path, out int splitIndex)
        {
            splitIndex = -1;
            if (!TarCommon.IsASCII(path))
            {
                return(false);
            }

            for (int i = 0; i < path.Length; i++)
            {
                if (path[i] == '/')
                {
                    if (i < TarHeader.Prefix.Length && path.Length - i - 1 < TarHeader.Name.Length)
                    {
                        splitIndex = i;
                        return(true);
                    }
                }
            }

            return(false);
        }