Last active
December 15, 2015 05:49
-
-
Save BartlomiejSkwira/5211595 to your computer and use it in GitHub Desktop.
Using FileMAgic with Ruby to detect mime type
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
#prerequisites | |
#sudo apt-get install libmagic-dev | |
#https://github.com/blackwinter/ruby-filemagic | |
require 'filemagic' | |
puts FileMagic.new(FileMagic::MAGIC_MIME).file(__FILE__) | |
# => text/x-ruby; charset=us-ascii | |
#OR | |
fm = FileMagic.new | |
=> #<FileMagic:0x7fd4afb0> | |
fm.file('foo.zip') | |
=> "Zip archive data, at least v2.0 to extract" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment