Determine file type in Ruby

后端 未结 13 1091
耶瑟儿~
耶瑟儿~ 2020-11-30 22:21

How does one reliably determine a file\'s type? File extension analysis is not acceptable. There must be a rubyesque tool similar to the UNIX file(1) comman

13条回答
  •  我在风中等你
    2020-11-30 22:49

    Pure Ruby solution using magic bytes and returning a symbol for the matching type:

    https://github.com/SixArm/sixarm_ruby_magic_number_type

    I wrote it, so if you have suggestions, let me know.

提交回复
热议问题