R/mime.r

Defines functions mime_type

Documented in mime_type

#' Compute mime type from file extension.
#' Needs mechanism for user extension.
#'
#' @param path path to file
#' @return mime string
mime_type <- function(path) {
  ext <- strsplit(path, ".", fixed = TRUE)[[1L]]
  n <- length(ext)
  
  if (n == 0) return()
  
  types <- c(
    "css" = "text/css",
    "png" = "image/png",
    "tiff", "image/tiff",
    "gif" = "image/gif", # in R2HTML
    "js" = "text/javascript",
    "jpeg" = "image/jpeg",
    "jpg" = "image/jpeg",
    "html" = "text/html",
    "ico" = "image/x-icon",
    "pdf" = "application/pdf",
    "eps" = "application/postscript",
    "ps" = "application/postscript", # in GLMMGibbs, mclust
    "sgml"= "text/sgml", # in RGtk2
    "xml" = "text/xml",  # in RCurl
    "text/plain"
  )
  
  unname(types[ext[n]])
}
hadley/sinartra documentation built on May 17, 2019, 12:47 p.m.