-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
dune exec --no-print-directory ./mimetype.exe -- $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let () = | ||
let fname = Sys.argv.(1) in | ||
let mime = try Metadata.MIME.of_file fname with Not_found -> "unknown" in | ||
print_endline mime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(** Guess the mime-type of a file. *) | ||
|
||
let prefixes = | ||
[ | ||
"ID3", "audio/mpeg"; | ||
"OggS", "audio/ogg"; | ||
"%PDF-", "application/pdf"; | ||
"\137PNG\013\010\026\010", "image/png"; | ||
] | ||
|
||
let of_string s = | ||
let ans = ref "" in | ||
try | ||
List.iter | ||
(fun (prefix, mime) -> | ||
if String.starts_with ~prefix s then | ||
( | ||
ans := mime; | ||
raise Exit | ||
) | ||
) prefixes; | ||
raise Not_found | ||
with | ||
| Exit -> !ans | ||
|
||
let of_file fname = | ||
let len = 10 in | ||
let buf = Bytes.create len in | ||
let ic = open_in fname in | ||
let n = input ic buf 0 len in | ||
let buf = if n = len then buf else Bytes.sub buf 0 n in | ||
let s = Bytes.unsafe_to_string buf in | ||
of_string s |