This repository has been archived by the owner on Jul 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
70 lines (49 loc) · 2.55 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
output: rmarkdown::github_document
---
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active)
[![Travis-CIBuild Status](https://travis-ci.org/hrbrmstr/simplemagic.svg?branch=master)](https://travis-ci.org/hrbrmstr/simplemagic)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/simplemagic?branch=master&svg=true)](https://ci.appveyor.com/project/hrbrmstr/simplemagic)
[![Coverage Status](https://img.shields.io/codecov/c/github/hrbrmstr/simplemagic/master.svg)](https://codecov.io/github/hrbrmstr/simplemagic?branch=master)
# simplemagic
Lightweight File 'MIME' Type Detection Based On Contents or Extension
## 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 limited "magic" tests as well
as mapping 'MIME' types from a database of over 1,500 extension mappings.
Provides a more portable/ligtweight alternative to the `wand` package.
## 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`](https://github.com/threatstack/libmagic/tree/master/magic/) 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.
## What's Inside The Tin
- `get_content_type`: Discover MIME type of a file based on contents
- `guess_content_type`: Guess MIME type from filename (extension)
- `simplemagic_mime_db`: File extension-to-MIME mapping data frame
The following functions are implemented:
## Installation
```{r eval=FALSE}
devtools::install_github("hrbrmstr/simplemagic")
```
```{r message=FALSE, warning=FALSE, error=FALSE, include=FALSE}
options(width=120)
```
## Usage
```{r message=FALSE, warning=FALSE, error=FALSE}
library(simplemagic)
library(tidyverse)
# current verison
packageVersion("simplemagic")
```
```{r}
list.files(system.file("extdat", package="simplemagic"), full.names=TRUE) %>%
map_df(~{
data_frame(
fil = basename(.x),
mime = list(get_content_type(.x))
)
}) %>%
unnest() %>%
print(n=100)
```
## Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.