package conan-unix

  1. Overview
  2. Docs
Identify type of your file (such as the MIME type)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

conan-0.0.8.tbz
sha256=478c6ddac4fb3c3f43e9f7c71be1aa309d18f09b47e097fc9b3e5dcd047537c5
sha512=3658ab6cfc673fab0bb03915289d552b8147f7a93c084f6e63c4b64573dd11927c9f107547fade87a7415f320d1cf4c2adc8bea6a71d59c6f2b7326f84cd5710

doc/conan-unix/Conan_unix/index.html

Module Conan_unixSource

File recognition.

Conan_unix provides few functions to recognize the MIME type of a given file. It implements unix routines to execute a decision tree Conan.Tree.t into a file accessible via a given path.

The Conan.Tree.t can come from a database available into a specific directory (see conan-cli) or the user can build/unserialize it from somewhere else.

Let's play with Conan_unix such as "/home/conan/database" contains our database (see conan or man magic to understand the format of the database). You must unserialize it to get the decision tree via:

let tree = Conan_unix.tree ~directory:"/home/conan/database"

From this tree, you can process it with a file accessible via a path. Let's say that, we want to recognize the type of "/home/conan/file", we just need:

let metadata =
  match Conan_unix.run_with_tree tree "/home/conan/file" with
  | Ok m -> m
  | Error (`Msg err) -> failwith err

An equivalent of the code above is:

let metadata =
  match
    Conan_unix.run ~database:"/home/conan/database" "/home/conan/file"
  with
  | Ok m -> m
  | Error (`Msg err) -> failwith err

Finally, you are able to generate a decision tree from a string instead of a directory (as before) with tree_of_string. Then, you are able to merge it with another decision tree via Conan.Tree.merge.

Metadata.

The returned metadata gives you two informations: 1) a possible output which describes the given file 2) a possible MIME type

You can get the output description Conan.Metadata.output and the MIME type via Conan.Metadata.mime. These informations are optional - the decision tree can finish without any information.

Sourceval tree : directory:string -> Conan.Tree.t

tree ~directory generates a Conan.Tree.t from the given directory. It will scan any files from the directory (but it does not do a recursive traverse) and it ignores any malformed files.

Sourceval tree_of_string : string -> (Conan.Tree.t, [> `Msg of string ]) result

tree_of_string str tries to construct from the given str a Conan.Tree.t.

Sourceval run_with_tree : Conan.Tree.t -> string -> (Conan.Metadata.t, [> `Msg of string ]) result

run_with_tree tree filename executes the given decision tree on the file accessible via the path filename.

Sourceval run : database:string -> string -> (Conan.Metadata.t, [> `Msg of string ]) result

run ~database filename executes the Conan.Tree.t which results from the given directory database on the file accessible via the path filename.