The byte patterns of the MIME Sniffing Standard, and the functions that match them against the first bytes of a resource.
The bytes are a byte array on the JVM and a Uint8Array in ClojureScript (a Node Buffer is one). Only the first 1445 count, so a whole body will do. A function returns a MIME type as text, e.g. image/png, or nil when nothing matches.
A row of a table is a map of:
The byte patterns of the MIME Sniffing Standard, and the functions that match them against the first bytes of a resource. The bytes are a byte array on the JVM and a Uint8Array in ClojureScript (a Node Buffer is one). Only the first 1445 count, so a whole body will do. A function returns a MIME type as text, e.g. image/png, or nil when nothing matches. A row of a table is a map of: - :pattern, the bytes to match, with :tt for a space or > after a tag - :mask, how much of each byte counts: all of it for 0xFF, all but the case of a letter for 0xDF, and none of it for 0x00 - :ignored, the bytes that may come before the pattern - :type, the MIME type of a match
The table of archive patterns.
The table of archive patterns.
(archive-type b)The archive type that the bytes b match, or nil.
The archive type that the bytes `b` match, or nil.
The table of audio and video patterns. The checks for MP4, WebM and MP3 without ID3 come after it.
The table of audio and video patterns. The checks for MP4, WebM and MP3 without ID3 come after it.
(audio-or-video-type b)The audio or video type that the bytes b match, or nil.
The audio or video type that the bytes `b` match, or nil.
(feed-type b)The feed type that the bytes b start with, application/rss+xml or
application/atom+xml, or nil.
The standard had these rules for a feed served as HTML until 15 July 2024, when it dropped them because no browser follows them. A feed starts with the root element of RSS, Atom or RSS 1.0, after any comments, declarations and processing instructions.
The feed type that the bytes `b` start with, application/rss+xml or application/atom+xml, or nil. The standard had these rules for a feed served as HTML until 15 July 2024, when it dropped them because no browser follows them. A feed starts with the root element of RSS, Atom or RSS 1.0, after any comments, declarations and processing instructions.
(font-type b)The font type that the bytes b match, or nil.
The font type that the bytes `b` match, or nil.
(image-type b)The image type that the bytes b match, or nil.
The image type that the bytes `b` match, or nil.
(matches? b pattern mask ignored)Whether the bytes b match the pattern under the mask, after any
leading bytes in the set ignored.
Whether the bytes `b` match the `pattern` under the `mask`, after any leading bytes in the set `ignored`.
The most bytes of a resource that sniffing reads.
The most bytes of a resource that sniffing reads.
The table of HTML, XML and PDF patterns, which unknown-type tries only when asked to.
The table of HTML, XML and PDF patterns, which unknown-type tries only when asked to.
(text-or-binary b)The type of a resource served as plain text, by its first bytes b:
text/plain, or application/octet-stream when they hold a binary control
and no byte order mark.
The type of a resource served as plain text, by its first bytes `b`: text/plain, or application/octet-stream when they hold a binary control and no byte order mark.
The table of PostScript and the byte order marks of text, which unknown-type always tries.
The table of PostScript and the byte order marks of text, which unknown-type always tries.
(unknown-type b)(unknown-type b scriptable?)The type of a resource of unknown type, by its first bytes b, with
HTML, XML and PDF among the candidates when scriptable?.
When no table matches, it's text/plain, or application/octet-stream when the bytes hold a control other than tab, LF, FF, CR or ESC.
The type of a resource of unknown type, by its first bytes `b`, with HTML, XML and PDF among the candidates when `scriptable?`. When no table matches, it's text/plain, or application/octet-stream when the bytes hold a control other than tab, LF, FF, CR or ESC.
The bytes that some patterns ignore before them: tab, LF, FF, CR and space.
The bytes that some patterns ignore before them: tab, LF, FF, CR and space.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |