Title: | Retrieve Magic Attributes from Files and Directories |
---|---|
Description: | MIME types are shorthand descriptors for file contents and can be determined from "magic" bytes in file headers, file contents or intuited from file extensions. Tools are provided to perform curated "magic" tests as well as mapping MIME types from a database of over 1,800 extension mappings. |
Authors: | Bob Rudis [aut, cre] |
Maintainer: | Bob Rudis <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.6.0 |
Built: | 2024-10-31 21:07:54 UTC |
Source: | https://gitlab.com/hrbrmstr/wand |
There are a limited number of header "magic" bytes checked directly by
this function but cover quite a bit of ground. After that, guess_content_type()
is called which uses file extension-to-MIME mappings.
get_content_type(path, guess = TRUE, ...)
get_content_type(path, guess = TRUE, ...)
path |
path to a file |
guess |
if |
... |
passed on to |
File an issue or PR if more magic-byte-level
comparisons are required/desired. If no match is found, ???
is returned
(see guess_content_type()
for how to override this behaviour).
character vector
get_content_type(system.file("extdat", "pass-through", "test.pdf", package="wand"))
get_content_type(system.file("extdat", "pass-through", "test.pdf", package="wand"))
Uses an internal database of over 1,800 file extension-to-MIME mappings to
return one or more associated types for a given input path. If no match is
found, ???
is returned.
guess_content_type(path, not_found = "???", custom_db = NULL)
guess_content_type(path, not_found = "???", custom_db = NULL)
path |
path to file |
not_found |
MIME type to use when the content cannot be guessed by file type. |
custom_db |
a single data frames each with two columns:
|
character vector
guess_content_type(system.file("extdat", "pass-through", "test.pdf", package="wand"))
guess_content_type(system.file("extdat", "pass-through", "test.pdf", package="wand"))
built from the files found in the References
Last updated 2019-07-27.
- <https://tools.ietf.org/html/rfc6838> - <https://www.iana.org/assignments/media-types/media-types.xhtml> - <https://s-randomfiles.s3.amazonaws.com/mime/allMimeTypes.json> - <https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json>
The 'libmagic' library provides functions to determine 'MIME' type and other metadata from files through their "magic" attributes. This is useful when you do not wish to rely solely on the honesty of a user or the extension on a file name. It also incorporates other metadata from the mime-db database https://github.com/jshttp/mime-db
The header checking is minimal (i.e. nowhere near as comprehensive as libmagic
) but
covers quite a bit of ground. If there are content-check types from
magic sources
that you would like coded into the package, please file an issue and
include the full line(s) from that linked magic.tab
that you would like mapped.
Bob Rudis ([email protected])