Class: Excavate::FileMagic
- Inherits:
-
Object
- Object
- Excavate::FileMagic
- Defined in:
- lib/excavate/file_magic.rb
Class Method Summary collapse
Instance Method Summary collapse
- #detect ⇒ Object
-
#initialize(path) ⇒ FileMagic
constructor
A new instance of FileMagic.
Constructor Details
#initialize(path) ⇒ FileMagic
Returns a new instance of FileMagic.
7 8 9 |
# File 'lib/excavate/file_magic.rb', line 7 def initialize(path) @path = path end |
Class Method Details
.detect(path) ⇒ Object
3 4 5 |
# File 'lib/excavate/file_magic.rb', line 3 def self.detect(path) new(path).detect end |
Instance Method Details
#detect ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/excavate/file_magic.rb', line 11 def detect beginning = File.read(@path, 8, mode: "rb") case beginning when "MSCF\x00\x00\x00\x00".force_encoding("BINARY") :cab else case beginning.byteslice(0, 2) when "\x1F\x8B".force_encoding("BINARY") :gzip end end end |