Пример #1
0
        private bool ReadBoundary()
        {
            try
            {
                string line = ReadLine();
                while (line == "")
                {
                    line = ReadLine();
                }
                if (line[0] != '-' || line[1] != '-')
                {
                    return(false);
                }

                if (!StrUtils.EndsWith(line, boundary, false))
                {
                    return(true);
                }
            }
            catch
            {
            }

            return(false);
        }
Пример #2
0
        public Element ReadNextElement()
        {
            if (_atEof || ReadBoundary())
            {
                return(null);
            }

            var    elem = new Element();
            string header;

            while ((header = ReadHeaders()) != null)
            {
                if (StrUtils.StartsWith(header, "Content-Disposition:", true))
                {
                    elem.Name     = GetContentDispositionAttribute(header, "name");
                    elem.Filename = StripPath(GetContentDispositionAttributeWithEncoding(header, "filename"));
                }
                else if (StrUtils.StartsWith(header, "Content-Type:", true))
                {
                    elem.ContentType = header.Substring("Content-Type:".Length).Trim();
                }
            }

            long start = data.Position;

            elem.Start = start;
            long pos = MoveToNextBoundary();

            if (pos == -1)
            {
                return(null);
            }

            elem.Length = pos - start;
            return(elem);
        }