Skip to content

Instantly share code, notes, and snippets.

@BartlomiejSkwira
Last active December 15, 2015 05:49
Show Gist options
  • Save BartlomiejSkwira/5211595 to your computer and use it in GitHub Desktop.
Save BartlomiejSkwira/5211595 to your computer and use it in GitHub Desktop.
Using FileMAgic with Ruby to detect mime type
#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