Ejemplo n.º 1
0
        public override ContentInfo Use(Stream stream)
        {
            ContentInfo result = null;

            var buffer = ByteUtils.GetBuffer(stream, 2048);

            var s = (TextHelper.IsUnicode(buffer) ? Encoding.Unicode.GetString(buffer) : Encoding.ASCII.GetString(buffer)).ToLower();

            if (
                s.Contains("<!doctype html") ||
                s.Contains("<html") ||
                s.Contains("<head") ||
                s.Contains("<body"))
            {
                result = ContentSpecs.First(t => t.ContentType == ContentTypes.HTML);
            }

            if (
                s.Contains("<!doctype xhtml") ||
                s.Contains("<xhtml")
                )
            {
                result = ContentSpecs.First(t => t.ContentType == XHTML);
            }


            return(result);
        }
Ejemplo n.º 2
0
        public override ContentInfo Use(Stream source)
        {
            ContentInfo result = null;

            var buffer    = ByteUtils.GetBuffer(source, (int)source.Length);
            var isUnicode = TextHelper.IsUnicode(buffer);

            if (isUnicode)
            {
                return(ContentSpecs.First(t => t.ContentType == ContentTypes.Text));
            }
            else
            {
                return(ContentSpecs.First(t => t.ContentType == ContentTypes.ASCII));
            }
            return(null);
        }