Sha256: 0450d7f2d746003fe061d5a67d1939f1297e5c52c55b3da50ff33f624c2f13dc

Contents?: true

Size: 458 Bytes

Versions: 4

Compression:

Stored size: 458 Bytes

Contents

module Excavate
  class FileMagic
    def self.detect(path)
      new(path).detect
    end

    def initialize(path)
      @path = path
    end

    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
excavate-0.3.7 lib/excavate/file_magic.rb
excavate-0.3.6 lib/excavate/file_magic.rb
excavate-0.3.5 lib/excavate/file_magic.rb
excavate-0.3.4 lib/excavate/file_magic.rb