Skip to content

MagicNumber is the module to determine a file's type from its magic number.

License

Notifications You must be signed in to change notification settings

ishikawa/elixir-magic-number

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MagicNumber

CI Status Hex.pm Hexdocs.pm

MagicNumber is the module to determine a file's type from its magic number.

It is currently heavily under development, The public API should not be considered stable.

Installation

The package can be installed from Hex as:

Add magic_number to your list of dependencies in mix.exs:

def deps do
  [{:magic_number, "~> 0.0.4"}]
end

Ensure magic_number is started before your application:

def application do
  [applications: [:magic_number]]
end

Usage

% iex -S mix
...
iex(1)> content = File.read!("sample.gif")
<<71, 73, 70, 56, 55, 97, 64, 0, 64, 0, 145, 0, 0, 0, 0, 0, 134, 195, 81, 255, 255, 255, 0, 0, 0, 33, 249, 4, 9, 0, 0, 3, 0, 33, 255, 11, 73, 67, 67, 82, 71, 66, 71, 49, 48, 49, 50, 255, 0, 0, ...>>
iex(2)> MagicNumber.detect(content)
{:ok, {:image, :gif}}

Supported file types

  • image/jpeg
  • image/png
  • image/gif
  • image/tiff
  • application/pdf
  • application/zip
  • application/gzip

License

MIT

About

MagicNumber is the module to determine a file's type from its magic number.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages