FileMagic is a Ruby binding to the magic(4) library, which you may know better as the file(1) command. The file(1) command identifies the type of a file using, among other tests, a test for whether the file begins with a certain magic number.