MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / detect_mime

Function detect_mime

crates/opencode-tool/src/read.rs:201–231  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

199}
200
201fn detect_mime(path: &Path) -> String {
202 let ext = path
203 .extension()
204 .and_then(|e| e.to_str())
205 .map(|e| e.to_lowercase())
206 .unwrap_or_default();
207
208 match ext.as_str() {
209 "png" => "image/png",
210 "jpg" | "jpeg" => "image/jpeg",
211 "gif" => "image/gif",
212 "webp" => "image/webp",
213 "bmp" => "image/bmp",
214 "ico" => "image/x-icon",
215 "tiff" | "tif" => "image/tiff",
216 "avif" => "image/avif",
217 "heic" | "heif" => "image/heic",
218 "pdf" => "application/pdf",
219 "json" => "application/json",
220 "html" | "htm" => "text/html",
221 "css" => "text/css",
222 "js" => "application/javascript",
223 "ts" => "application/typescript",
224 "md" => "text/markdown",
225 "txt" => "text/plain",
226 "xml" => "application/xml",
227 "svg" => "image/svg+xml",
228 _ => "application/octet-stream",
229 }
230 .to_string()
231}
232
233fn is_image_mime(mime: &str) -> bool {
234 mime.starts_with("image/") && mime != "image/svg+xml" && mime != "image/vnd.fastbidsheet"

Callers 1

executeMethod · 0.85

Calls 1

as_strMethod · 0.45

Tested by

no test coverage detected