jhn_magic (jhn_stdlib v5.10.3)

View Source

A media type determining library based on a subset of the types found in:

https://www.iana.org/assignments/media-types/media-types.xhtml

The trivially determined types are:

application/applefile application/gzip (rfc6713) application/msword application/pdf (rfc8118) application/postscript (rfc2045) application/rtf application/sqlite3 application/vnd.ms-excel application/vnd.ms-powerpoint application/vnd.visio application/zip image/bmp (rfc7903) image/jpeg (rfc2046) image/png (https://www.w3.org/TR/png/) image/vnd.microsoft.icon image/webp (rfc9649) text/calendar (rfc5545)

The following types requires deeper analysis possibly including uncompressing the file and are only determined when the {deep, true} option is provided, if not the encapsulating type, e.g., application/zip.

application/atom+xml (rfc4287) application/epub+zip (https://www.w3.org/TR/epub-overview-33/) application/vnd.ms-visio.drawing.main+xml application/vnd.openxmlformats-officedocument.wordprocessingml.document application/ vnd.openxmlformats-officedocument.presentationml.presentation application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

So far only a few types are supported but more will be added.

Summary

Functions

Equivalent of calling check(MediaType(s) File, [])

The files media type is checked against the type or types provided and if they are the same or a member true is returned otherwise false.

Equivalent of calling media_type(File, [])

The files media type is returned.

Types

media_type/0

-type media_type() :: binary().

opt/0

-type opt() :: {atom(), _}.

opts/0

-type opts() :: [opt()].

Functions

check(Types, File)

-spec check(binary() | [binary()], binary()) -> boolean().

Equivalent of calling check(MediaType(s) File, [])

check(Types, File, Opts)

-spec check(binary() | [binary()], binary(), opts()) -> boolean().

The files media type is checked against the type or types provided and if they are the same or a member true is returned otherwise false.

Options are: {deep, boolean()} -> does more expensive analysis default false

media_type(File)

-spec media_type(binary()) -> media_type() | undefined.

Equivalent of calling media_type(File, [])

media_type(File, Opts)

-spec media_type(binary(), opts()) -> media_type() | undefined.

The files media type is returned.

Options are: {deep, boolean()} -> does more expensive analysis default false