Beispiel #1
0
        private bool ReadBoundary()
        {
            try
            {
                var line = ReadLine();
                while (line == "")
                {
                    line = ReadLine();
                }
                if (line[0] != '-' || line[1] != '-')
                {
                    return(false);
                }

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

            return(false);
        }
Beispiel #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();
                }
            }

            var start = data.Position;

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

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

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