Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: File::MMagic returns application/octet-stream for most files

by Your Mother (Archbishop)
on Jan 23, 2016 at 17:31 UTC ( [id://1153471]=note: print w/replies, xml ) Need Help??


in reply to File::MMagic returns application/octet-stream for most files

Sounds like your system magic file is actually not being read maybe. Have you tried the default File::MMagic->new() just to see? Works well for me (using 1.27 on Perl 5.8.8 to do a couple tests right now) in plain cases like you describe. Can you show a minimal code example that fails for you?

  • Comment on Re: File::MMagic returns application/octet-stream for most files

Replies are listed 'Best First'.
Re^2: File::MMagic returns application/octet-stream for most files
by ajlittoz (Novice) on Jan 23, 2016 at 20:43 UTC

    Yes, I forced File::MMagic->new() and printed what was returned from checktype_contents(). It is invariably application/octet-stream which makes me think that the reference to the system magic file has been lost between the time I constructed a new MMagic object and it is used (although I dumped the object variable and that shows the same address).

    My version is 1.27 like yours, Perl is v5.14.4.

    Here is part of my initialisation code. As you can see, I have commented out references to magic files (the system file name is passed through hash member 'magicmime' while a fall-back file exists in the private library lib. The initial part of the file to test is read-in separately before calling one of the two functions defined in the "configuration" hash.

    my $magic = File::MMagic->new ( # -f $self->{'magicmime'} # ? $self->{'magicmime'} # : -f 'lib/magic.mime' ? 'lib/magic +.mime' : () ); $self->{'&discard'} = sub { 'text/' ne substr($magic->checktype_co +ntents(@_[0]), 0, 5) }; # Same, to return the complete MIME type $self->{'&mimetype'} = sub {$magic->checktype_contents(@_[0])};

    Function &discard seems to work fine (at least it returns true on text files). Function &mimetype returns either text/plain or application/octet-stream on my test files.

    I may have made a big mistake in my code as I'm using a non-scope variable binding for $magic: when the functions are called, the block containing my $magic has disappeared for a long time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1153471]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found