SultanC
  1. Home
  2. Examples
  3. Web

Choosing a media type from a file name

web/mime_types.sn
// Choosing a media type from a file name.
import std.io.println;
import std.mime.mime;

def main(): int {
    let page: string = "index.html";
    let picture: string = "logo.png";
    let unknown: string = "archive.unknownext";
    let page_type: mime_type = mime_type_from_path_or_default(&page);
    let picture_type: mime_type = mime_type_from_path_or_default(&picture);
    let unknown_type: mime_type = mime_type_from_path_or_default(&unknown);
    println(mime_type_text(&page_type));
    println(mime_type_text(&picture_type));
    println(mime_type_text(&unknown_type));
    return 0;
}

Run it

With the interpreter, without compiling:

./build/sultanc run examples/en/web/mime_types.sn

Or compile it to an executable:

./build/sultanc examples/en/web/mime_types.sn -o build/example && ./build/example

Source on GitHub   All examples