/// <summary>Examines the a file's first bytes and estimates the file's type.</summary>
        /// <exception cref="ArgumentException">Stream does not support seeking.</exception>
        /// <exception cref="IOException">if an IO error occurred or the input stream ended unexpectedly.</exception>
        public static FileType DetectFileType([NotNull] Stream stream)
        {
            if (!stream.CanSeek)
            {
                throw new ArgumentException("Must support seek", nameof(stream));
            }

            var maxByteCount = _root.MaxDepth;

            var bytes     = new byte[maxByteCount];
            var bytesRead = stream.Read(bytes, 0, bytes.Length);

            if (bytesRead == 0)
            {
                return(FileType.Unknown);
            }

            stream.Seek(-bytesRead, SeekOrigin.Current);

            var fileType = _root.Find(bytes);

            if (fileType == FileType.Unknown)
            {
                foreach (var fixedChecker in _fixedCheckers)
                {
                    fileType = fixedChecker(bytes);
                    if (fileType != FileType.Unknown)
                    {
                        return(fileType);
                    }
                }
            }

            return(fileType);
        }
        /// <summary>Examines the a file's first bytes and estimates the file's type.</summary>
        /// <exception cref="ArgumentException">Stream does not support seeking.</exception>
        /// <exception cref="IOException">An IO error occurred, or the input stream ended unexpectedly.</exception>
        public static FileType DetectFileType([NotNull] Stream stream)
        {
            if (!stream.CanSeek)
            {
                throw new ArgumentException("Must support seek", nameof(stream));
            }

            var maxByteCount = _root.MaxDepth;

            var bytes     = new byte[maxByteCount];
            var bytesRead = stream.Read(bytes, 0, bytes.Length);

            if (bytesRead == 0)
            {
                return(FileType.Unknown);
            }

            stream.Seek(-bytesRead, SeekOrigin.Current);

            var fileType = _root.Find(bytes);

            if (fileType == FileType.Unknown)
            {
                foreach (var fixedChecker in _fixedCheckers)
                {
                    fileType = fixedChecker(bytes);
                    if (fileType != FileType.Unknown)
                    {
                        return(fileType);
                    }
                }
            }
            else if (fileType == FileType.Riff)
            {
                var fourCC = Encoding.UTF8.GetString(bytes, index: 8, count: 4);
                switch (fourCC)
                {
                case "WAVE":
                    return(FileType.Wav);

                case "AVI ":
                    return(FileType.Avi);

                case "WEBP":
                    return(FileType.WebP);
                }
            }

            return(fileType);
        }