Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-04-2024, 02:11 AM
|
#1
|
Senior Member
Registered: Dec 2015
Posts: 1,639
Rep:
|
[Ruby FileMagic] Checks on ARGF (STDIN)
Good morning
I must verify Mime-types and/or the Magic of data which is read via STDIN (ARGF in Ruby ... and others) (I presume)
The only thing that I can currently come up with, this morning, under pressure of time, is a temporary file.
So basically, I *can* do what I want. But I find it clumsy and ugly.
AFAIS the obstruction comes from the limited functionality of the FileMagic gem, but I may be erring (StreamMagic or STDINMagic is what I seek, I guess).
Would anybody have a better idea? Do as if I was starting to program and this were my very first project, ever. “Wrong project!” would be a pertinent answer, but let us exclude this for now. TY.
TY.
Last edited by Michael Uplawski; 07-04-2024 at 02:13 AM.
Reason: readability.
|
|
|
07-04-2024, 03:27 AM
|
#2
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,923
|
Guess you mean you wish to use `libmagic` or `file` utility in your program.
|
|
|
07-04-2024, 04:16 AM
|
#3
|
Senior Member
Registered: Mar 2020
Posts: 3,706
Rep:
|
There are four Ruby gems (listed here in the order of their popularity): Which one do you use?
E.g. using ruby-filemagic
Code:
$ ruby -rfilemagic -e 'puts FileMagic.mime.file $<.filename' README.md
text/plain; charset=utf-8
Code:
$ ruby -rfilemagic -e 'puts FileMagic.mime.buffer $<.read' <README.md
text/plain; charset=utf-8
The same using magic
Code:
$ ruby -rmagic -e 'puts Magic.guess_file_mime $<.filename' README.md
text/plain; charset=utf-8
Code:
$ ruby -rmagic -e 'puts Magic.guess_string_mime $<.read' <README.md
text/plain; charset=utf-8
The same using ruby-magic
Code:
$ ruby -rmagic/magic -rmagic -e'puts File.mime$<.filename' README.md
text/plain; charset=utf-8
Code:
$ ruby -rmagic/magic -rmagic -e'puts$<.read.mime' <README.md
text/plain; charset=utf-8
Last edited by shruggy; 07-05-2024 at 04:33 AM.
|
|
1 members found this post helpful.
|
07-04-2024, 04:09 PM
|
#4
|
Senior Member
Registered: Dec 2015
Posts: 1,639
Original Poster
Rep:
|
I am using ruby-filemagic.
It looks as if I have not understood ARGF.filename, nor ARGF.read.
TY.
|
|
|
07-05-2024, 04:17 PM
|
#5
|
Senior Member
Registered: Dec 2015
Posts: 1,639
Original Poster
Rep:
|
Good evening
FileMagic.mime.buffer is not documented, it seems.
But I am using it now.
|
|
|
07-06-2024, 06:26 AM
|
#6
|
Senior Member
Registered: Mar 2020
Posts: 3,706
Rep:
|
It is a shortcut for FileMagic.open(:mime).buffer as described here.
|
|
|
07-07-2024, 02:28 PM
|
#7
|
Senior Member
Registered: Dec 2015
Posts: 1,639
Original Poster
Rep:
|
Maybe I am able to understand Ruby and some Modules, but unable to cope with the documentation.
|
|
|
All times are GMT -5. The time now is 02:20 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|