From: Wes Gamble Date: 2006-03-22T09:18:45+09:00 Subject: Re: Newbie: Better way to check a magic number on a file? An even better way would be to take advantage of the fact that I'm uploading through a browser and just look at the MIME type :) :) :) Man, I'm dumb :). But on the other hand, now I now about the IO module, and modules in general and all kinds of things. Thanks, everybody. Wes Mike Stok wrote: > On 21-Mar-06, at 6:46 PM, Wes Gamble wrote: > >> magic_number = nil >> >> Should magic_number.eql?('d0cf11e0a1b1') work? > > There are a number of simpler ways, one might be > > EXCEL_FILE_MAGIC_NUMBER = ['d0cf11e0a1b1'].pack('H*') > > # later > > magic_number == EXCEL_FILE_MAGIC_NUMBER # => true or false > > or you can use octal or hex escapes to have a string literal to > compare against e.g. > > irb(main):006:0> "\320\317\021\340\241\261" == "\xd0\xcf\x11\xe0\xa1 > \xb1" > => true > > Maybe there are good bits of the Pickaxe (Programming Ruby) or some > on-line tutorials which can help you see some of the more ruby-ish > ways to do things. > > Hope this helps, > > Mike > > -- > > Mike Stok > http://www.stok.ca/~mike/ > > The "`Stok' disclaimers" apply. -- Posted via http://www.ruby-forum.com/.