Type: Package
Title: Retrieve 'Magic' Attributes from Files and Directories
Version: 0.5.0
Date: 2019-07-06
Maintainer: Bob Rudis <bob@rud.is>
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,500 extension mappings.
URL: http://gitlab.com/hrbrmstr/wand
BugReports: https://gitlab.com/hrbrmstr/wand/issues
Encoding: UTF-8
License: MIT + file LICENSE
Suggests: covr, tinytest
Imports: tools
Depends: R (≥ 3.2.0)
RoxygenNote: 6.1.1
NeedsCompilation: no
Packaged: 2019-07-08 18:28:20 UTC; hrbrmstr
Author: Bob Rudis ORCID iD [aut, cre]
Repository: CRAN
Date/Publication: 2019-07-08 18:50:10 UTC

Retrieve 'Magic' Attributes from Files and Directories

Description

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

Some important details

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.

Author(s)

Bob Rudis (bob@rud.is)


Discover MIME type of a file based on contents

Description

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. File an issue or PR if more magic-byte-level comparisons are required/desired. If no match is found, ??? is returned.

Usage

get_content_type(path)

Arguments

path

path to a file

Details

Initial in-R header mapping logic borrowed from MimeTypes.java from servoy-client

Value

character vector

Examples

get_content_type(system.file("extdat", "test.pdf", package="wand"))

Guess MIME type from filename (extension)

Description

Uses an internal database of over 1,500 file extension-to-MIME mappings to return one or more associated types for a given input path. If no match is found, ??? is returned.

Usage

guess_content_type(path)

Arguments

path

path to file

Details

Incorporates standard IANA MIME extension mappings and those from servoy-client and stevenwdv's allMimeTypes.json.

Value

character vector

Examples

guess_content_type(system.file("extdat", "test.pdf", package="wand"))

File extension-to-MIME mapping data frame

Description

File extension-to-MIME mapping data frame

Usage

simplemagic_mime_db

Format

An object of class tbl_df (inherits from tbl, data.frame) with 1763 rows and 2 columns.

mirror server hosted at Truenetwork, Russian Federation.