Class | FileMagic |
In: |
lib/filemagic.rb
lib/filemagic/version.rb |
Parent: | Object |
FLAGS_BY_SYM | = | [ :none, # No flags :debug, # Turn on debugging :symlink, # Follow symlinks :compress, # Check inside compressed files :devices, # Look at the contents of devices :mime_type, # Return only the MIME type :continue, # Return all matches :check, # Print warnings to stderr :preserve_atime, # Restore access time on exit :raw, # Don't translate unprint chars :error, # Handle ENOENT etc as real errors :mime_encoding, # Return only the MIME encoding :mime, # MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING :apple, # Return the Apple creator and type :no_check_compress, # Don't check for compressed files :no_check_tar, # Don't check for tar files :no_check_soft, # Don't check magic entries :no_check_apptype, # Don't check application type :no_check_elf, # Don't check for elf details :no_check_text, # Don't check for text files :no_check_cdf, # Don't check for cdf files :no_check_tokens, # Don't check ascii/tokens :no_check_encoding, # Don't check text encodings :no_check_ascii, # MAGIC_NO_CHECK_TEXT :no_check_fortran, # Don't check ascii/fortran :no_check_troff | Map flag names to their values (:name => Integer). | |
FLAGS_BY_INT | = | FLAGS_BY_SYM.invert.update(0 => :none) | Map flag values to their names (Integer => :name). | |
SIMPLE_RE | = | %r{([.\w\/-]+)} | Extract "simple" MIME type | |
VERSION | = | Version.to_s |
simplified | [W] |
Clear our instance cache.
# File lib/filemagic.rb, line 58 58: def clear! 59: @fm.each_value { |fm| fm.close } 60: @fm.clear 61: end
Provide a "magic singleton".
# File lib/filemagic.rb, line 52 52: def fm(*flags) 53: @fm.delete(flags.to_s) if @fm[flags].closed? 54: @fm[flags] 55: end
Just like new, but takes an optional block, in which case close is called at the end and the value of the block is returned.
# File lib/filemagic.rb, line 65 65: def open(*flags) 66: fm = new(*flags) 67: 68: if block_given? 69: begin 70: yield fm 71: ensure 72: fm.close 73: end 74: else 75: fm 76: end 77: end