diff options
author | James Every <devstopfix@gmail.com> | 2020-03-25 16:19:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-25 16:19:15 +0000 |
commit | 20c4068e5d8bd725c42513301b288094c8857041 (patch) | |
tree | bd226f972dfeaed7b11e76158ac1bd2243b89420 /README.md | |
parent | Merge commit '82cea2a0db4af442a3ea89a340e54fcd11cf8180' (diff) |
Convert to ports (#5)
* Remove erlexec dependency
* feat: async verify worker has started
* test: move infinite to script
* fix: timeout response
* fix: unix compile [Closes #169398412]
* feat: allow database patterns as worker param
This allows us to expand paths in an application, which is not possible from the configuration file.
* OTP 22 compatible with Elixir 1.7-1.10
* Install make on CI server
libmagic-dev contains magic.h
Fix this error:
** (Mix) Could not compile with "make" (exit status: 2).
* Fix make install
* Fix plurality
* Fix credo warning
* Allow multiple error messages
OS X and Linux return different errors messages.
* Allow named GenServer processes
* Types
* Disable test broken in ci
Works locally, not in CI.
test/gen_magic_test.exs:50
** (EXIT from #PID<0.1672.0>) shutdown
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 57 |
1 files changed, 52 insertions, 5 deletions
@@ -1,6 +1,8 @@ # GenMagic -**TODO: Add description** +Determine file type. Elixir bindings for [libmagic](http://man7.org/linux/man-pages/man3/libmagic.3.html). + +[![Build Status](https://travis-ci.org/devstopfix/gen_magic.svg?branch=release_v1)](https://travis-ci.org/devstopfix/gen_magic) ## Installation @@ -10,12 +12,57 @@ by adding `gen_magic` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:gen_magic, "~> 0.1.0"} + {:gen_magic, "~> 0.20"} ] end ``` -Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) -and published on [HexDocs](https://hexdocs.pm). Once published, the docs can -be found at [https://hexdocs.pm/gen_magic](https://hexdocs.pm/gen_magic). +## Usage + +The libmagic library requires a magic file which can be installed in various locations on your file system. A good way of locating it is given in the [config](config/config.exs): + +```elixir +database = [ + "/usr/local/share/misc/magic.mgc", + "/usr/share/file/magic.mgc", + "/usr/share/misc/magic.mgc" +] |> Enum.find(&File.exists?/1) +``` + +The GenServer SHOULD be run under a supervisor or a pool as it is designed to end should it receive any unexpected error. Here we run it under a supervisor: + +```elixir +{:ok, _} = Supervisor.start_link([ + {GenMagic.ApprenticeServer, + [database_patterns: [database], name: :gen_magic]}], + strategy: :one_for_one) +``` + +Now we can ask it to inspect a file: + +```elixir +> GenMagic.ApprenticeServer.file(:gen_magic, Path.expand("~/.bash_history")) +{:ok, [mime_type: "text/plain", encoding: "us-ascii", content: "ASCII text"]} +``` + +For a one shot test, use the helper method: + +```elixir +> GenMagic.perform(Path.join(File.cwd!(), "Makefile")) + +{:ok, + [ + mime_type: "text/x-makefile", + encoding: "us-ascii", + content: "makefile script, ASCII text" + ]} +``` + +## Soak test + +Run an endless cycle to prove that the GenServer is resilient: +```bash +find /usr/share/ -name *png | xargs mix run test/soak.exs +find . -name *ex | xargs mix run test/soak.exs +```
\ No newline at end of file |