mime_type: Get the MIME types of files

View source: R/base64.R

mime_typeR Documentation

Get the MIME types of files

Description

If the mime package is installed, call mime::guess_type(), otherwise use the system command file --mime-type to obtain the MIME type of a file. Typically, the file command exists on *nix. On Windows, the command should exist if Cygwin or Rtools is installed. If it is not found, .NET's MimeMapping class will be used instead (which requires the .NET framework).

Usage

mime_type(x, use_mime = loadable("mime"), empty = "text/plain")

Arguments

x

A vector of file paths.

use_mime

Whether to use the mime package.

empty

The MIME type for files without extensions (e.g., Makefile). If NA, the type will be obtained from system command. This argument is used only for use_mime = FALSE.

Value

A character vector of MIME types.

Note

When querying the MIME type via the system command, the result will be cached to xfun:::cache_dir(). This will make future queries much faster, since running the command in real time can be a little slow.

Examples


f = list.files(R.home("doc"), full.names = TRUE)
mime_type(f)
mime_type(f, FALSE)  # don't use mime
mime_type(f, FALSE, NA)  # run command for files without extension


yihui/xfun documentation built on Sept. 24, 2024, 11:53 p.m.