Created
January 28, 2013 11:34
-
-
Save stiandre/4654813 to your computer and use it in GitHub Desktop.
python-magic (libmagic python bindings)
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
#!/usr/bin/env python | |
# Install (ubuntu/debian): | |
# ------------------------ | |
# apt-get install python-magic | |
import magic | |
ms = magic.open(magic.MAGIC_NONE) | |
ms.load() | |
type = ms.file("/path/to/some/file") | |
print type | |
f = file("/path/to/some/file", "r") | |
buffer = f.read(4096) | |
f.close() | |
type = ms.buffer(buffer) | |
print type | |
ms.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment