Newbie: Better way to check a magic number on a file?



All,

I am trying to determine if I am dealing with an Excel file that I
upload to a Web server.

Here is the first test - to verify the magic number of the file that I
have:

#Check the magic number first to see if it's even an Office file

magic_number = nil
File.open(path_to_file, "r") do |f|
magic_number = f.read(6)
end
return false unless
magic_number.unpack('H*').to_s().eql?('d0cf11e0a1b1')

This seems a little bit less than optimal. I have to unpack my string
into an array and then reconvert it back to a string to compare it?

Surely there is a simpler way?

Should magic_number.eql?('d0cf11e0a1b1') work?

Wes

--
Posted via http://www.ruby-forum.com/.


.



Relevant Pages

  • Re: Uploading Large File to SQL
    ... However now when I'm upload a 500+mb file I run out of memory on the web server. ... private string SaveFileToSQL ... SqlDataAdapter myDataAdapter = new SqlDataAdapter ...
    (microsoft.public.sqlserver.programming)
  • Re: Uploading Large File to SQL
    ... However now when I'm upload a 500+mb file I run out of memory on the web server. ... private string SaveFileToSQL ... SqlDataAdapter myDataAdapter = new SqlDataAdapter ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Inet1 connecting but cant upload - any help appreciated
    ... I am using the Inet control to link to our web server. ... I can upload and download files using MS FrontPage without any trouble. ... Dim strDestinationFile As String ...
    (microsoft.public.vb.general.discussion)
  • Inet1 connecting but cant upload - any help appreciated
    ... I am using the Inet control to link to our web server. ... I can upload and download files using MS FrontPage without any trouble. ... Dim strDestinationFile As String ...
    (microsoft.public.vb.general.discussion)
  • Re: RegExp irregularity in JScript
    ... we believe the VBScript Regular Expression class (version 1.0 through ... It does not however, limit the string minimum 4, maximum 8 characters. ... Obviously the first test should test the length of the string, minimum 4, ...
    (microsoft.public.scripting.jscript)