Module: MagicBytes
Defined Under Namespace
Classes: FileType
Constant Summary collapse
- VERSION =
'1.0.1'
Instance Method Summary collapse
-
#detect(header_bytes) ⇒ Hash?
This is a line-for-line port of github.com/sindresorhus/file-type which is more than sufficient for our purposes.
-
#read_and_detect(io) ⇒ Hash?
Performs detection from a given IO or File.
Instance Method Details
#detect(header_bytes) ⇒ Hash?
This is a line-for-line port of github.com/sindresorhus/file-type which is more than sufficient for our purposes
23 24 25 26 |
# File 'lib/magic_bytes.rb', line 23 def detect(header_bytes) d = _detect(header_bytes) FileType.new(d.fetch(:ext), d.fetch(:mime)) end |
#read_and_detect(io) ⇒ Hash?
Performs detection from a given IO or File.
13 14 15 16 |
# File 'lib/magic_bytes.rb', line 13 def read_and_detect(io) n_bytes = 262 # The maximum length supported (needed for .tar archives) detect(io.read(n_bytes)) end |