MimeType
import "std/data" (included in import "std") · namespace std.data
Media (MIME) types by file extension and back, for serving files, naming uploads and setting Content-Type. Unknown extensions are application/octet-stream. isText and isCompressible say whether a type is readable text and whether it is worth compressing in transfer.
grav
import "std"
fn main() {
print(MimeType.of("report.PDF"))
print(MimeType.of("assets/app.woff2"))
print(MimeType.extensionOf("image/jpeg"))
print("${MimeType.isText("application/ld+json")} ${MimeType.isCompressible("image/png")}")
}application/pdf
font/woff2
jpg
true falseclass MimeType
Static members
static fn of(nameOrExtension: string) -> string— The type for a file name, path or bare extension ("pdf", ".pdf", "a/b.pdf").static fn extensionOf(mimeType: string) -> string— The usual extension for a type (without the dot), "" when unknown.static fn isText(mimeType: string) -> bool— Whether a type is text a person can read (text/*, JSON, XML, JavaScript, SVG...).static fn isCompressible(mimeType: string) -> bool— Whether the type is worth compressing for transfer (text, and a few binary formats that are not already compressed).