Class: LLM::Mime

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/shell/internal/llm.rb/lib/llm/mime.rb

Class Method Summary collapse

Class Method Details

.[](key) ⇒ String?

Lookup a mime type

Returns:

  • (String, nil)


12
13
14
15
16
# File 'lib/llm/shell/internal/llm.rb/lib/llm/mime.rb', line 12

def self.[](key)
  key = key.respond_to?(:path) ? key.path : key
  extname = (key =~ EXTNAME) ? key : File.extname(key)
  types[extname] || "application/octet-stream"
end

.typesHash

Returns a Hash of mime types

Returns:

  • (Hash)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/llm/shell/internal/llm.rb/lib/llm/mime.rb', line 21

def self.types
  @types ||= {
    # Images
    ".png" => "image/png",
    ".jpg" => "image/jpeg",
    ".jpeg" => "image/jpeg",
    ".webp" => "image/webp",
    ".gif" => "image/gif",
    ".bmp" => "image/bmp",
    ".tif" => "image/tiff",
    ".tiff" => "image/tiff",
    ".svg" => "image/svg+xml",
    ".ico" => "image/x-icon",
    ".apng" => "image/apng",
    ".jfif" => "image/jpeg",
    ".heic" => "image/heic",

    # Videos
    ".flv" => "video/x-flv",
    ".mov" => "video/quicktime",
    ".mpeg" => "video/mpeg",
    ".mpg" => "video/mpeg",
    ".mp4" => "video/mp4",
    ".webm" => "video/webm",
    ".wmv" => "video/x-ms-wmv",
    ".3gp" => "video/3gpp",
    ".avi" => "video/x-msvideo",
    ".mkv" => "video/x-matroska",
    ".ogv" => "video/ogg",
    ".m4v" => "video/x-m4v",
    ".m2ts" => "video/mp2t",
    ".mts" => "video/mp2t",

    # Audio
    ".aac" => "audio/aac",
    ".flac" => "audio/flac",
    ".mp3" => "audio/mpeg",
    ".m4a" => "audio/mp4",
    ".mpga" => "audio/mpeg",
    ".opus" => "audio/opus",
    ".pcm" => "audio/L16",
    ".wav" => "audio/wav",
    ".weba" => "audio/webm",
    ".oga" => "audio/ogg",
    ".ogg" => "audio/ogg",
    ".mid" => "audio/midi",
    ".midi" => "audio/midi",
    ".aiff" => "audio/aiff",
    ".aif" => "audio/aiff",
    ".amr" => "audio/amr",
    ".mka" => "audio/x-matroska",
    ".caf" => "audio/x-caf",

    # Documents
    ".pdf" => "application/pdf",
    ".txt" => "text/plain",
    ".md" => "text/markdown",
    ".markdown" => "text/markdown",
    ".mkd" => "text/markdown",
    ".doc" => "application/msword",
    ".docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    ".xls" => "application/vnd.ms-excel",
    ".xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    ".ppt" => "application/vnd.ms-powerpoint",
    ".pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
    ".csv" => "text/csv",
    ".json" => "application/json",
    ".xml" => "application/xml",
    ".html" => "text/html",
    ".htm" => "text/html",
    ".odt" => "application/vnd.oasis.opendocument.text",
    ".odp" => "application/vnd.oasis.opendocument.presentation",
    ".ods" => "application/vnd.oasis.opendocument.spreadsheet",
    ".rtf" => "application/rtf",
    ".epub" => "application/epub+zip",

    # Code
    ".js" => "application/javascript",
    ".jsx" => "text/jsx",
    ".ts" => "application/typescript",
    ".tsx" => "text/tsx",
    ".css" => "text/css",
    ".c" => "text/x-c",
    ".cpp" => "text/x-c++",
    ".h" => "text/x-c",
    ".rb" => "text/x-ruby",
    ".py" => "text/x-python",
    ".java" => "text/x-java-source",
    ".sh" => "application/x-sh",
    ".php" => "application/x-httpd-php",
    ".yml" => "text/yaml",
    ".yaml" => "text/yaml",
    ".go" => "text/x-go",
    ".rs" => "text/rust",

    # Fonts
    ".woff" => "font/woff",
    ".woff2" => "font/woff2",
    ".ttf" => "font/ttf",
    ".otf" => "font/otf",

    # Archives
    ".zip" => "application/zip",
    ".tar" => "application/x-tar",
    ".gz" => "application/gzip",
    ".bz2" => "application/x-bzip2",
    ".xz" => "application/x-xz",
    ".rar" => "application/vnd.rar",
    ".7z" => "application/x-7z-compressed",
    ".tar.gz" => "application/gzip",
    ".tar.bz2" => "application/x-bzip2",
    ".apk" => "application/vnd.android.package-archive",
    ".exe" => "application/x-msdownload",

    # Others
    ".ics" => "text/calendar",
    ".vcf" => "text/vcard"
  }
end