diff options
author | Adam Hupp <adam@hupp.org> | 2015-02-26 21:46:38 -0800 |
---|---|---|
committer | Adam Hupp <adam@hupp.org> | 2015-02-26 21:46:38 -0800 |
commit | 016ab238228a322371b400280fd5818827adcfc9 (patch) | |
tree | ea1e7f41cec1dca4926f9f4d3a0a5c1d5f282207 /README.md | |
parent | 221a407f5c68d74f8567383b8d000be2147a1eec (diff) | |
parent | e9376e2d81883a64067e7471be5bec15946e2fd4 (diff) | |
download | python-magic-016ab238228a322371b400280fd5818827adcfc9.tar.gz |
Merge pull request #74 from iiSeymour/patch-1
Updated README.md
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -8,13 +8,15 @@ functionality is exposed to the command line by the Unix command ## Usage - >>> import magic - >>> magic.from_file("testdata/test.pdf") - 'PDF document, version 1.2' - >>> magic.from_buffer(open("testdata/test.pdf").read(1024)) - 'PDF document, version 1.2' - >>> magic.from_file("testdata/test.pdf", mime=True) - 'application/pdf' +```python +>>> import magic +>>> magic.from_file("testdata/test.pdf") +'PDF document, version 1.2' +>>> magic.from_buffer(open("testdata/test.pdf").read(1024)) +'PDF document, version 1.2' +>>> magic.from_file("testdata/test.pdf", mime=True) +'application/pdf' +``` There is also a `Magic` class that provides more direct control, including overriding the magic database file and turning on character @@ -22,16 +24,20 @@ encoding detection. This is not recommended for general use. In particular, it's not safe for sharing across multiple threads and will fail throw if this is attempted. - >>> f = magic.Magic(uncompress=True) - >>> f.from_file('testdata/test.gz') - 'ASCII text (gzip compressed data, was "test", last modified: Sat Jun 28 - 21:32:52 2008, from Unix)' +```python +>>> f = magic.Magic(uncompress=True) +>>> f.from_file('testdata/test.gz') +'ASCII text (gzip compressed data, was "test", last modified: Sat Jun 28 +21:32:52 2008, from Unix)' +``` You can also combine the flag options: - >>> f = magic.Magic(mime=True, uncompress=True) - >>> f.from_file('testdata/test.gz') - 'text/plain' +```python +>>> f = magic.Magic(mime=True, uncompress=True) +>>> f.from_file('testdata/test.gz') +'text/plain' +``` ## Name Conflict |