0.0
No commit activity in last 3 years
No release in over 3 years
Basic file type checks based on a few header bytes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0
< 11
~> 3.2.0
>= 0
 Project Readme

A pretty much line-for-line port of https://github.com/sindresorhus/file-type Many thanks to Sindre Sorhus for putting this together.

The module has two methods: detect and read_and_detect. The former works on String objects (when you already read stuff), the latter works on IO objects (or anything you can #read from).

file_type = File.open('suspicious_file.bin', 'rb') do |f
  MagicBytes.read_and_detect(f)
end
file_type.ext #=> 'msi', someone is uploading a Windows installer...

If the file type is unknown, the last-resort variant of bin as extension and binary/octet-stream will be returned.