LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 07-04-2024, 02:11 AM   #1
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,639
Blog Entries: 40

Rep: Reputation: Disabled
[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.
 
Old 07-04-2024, 03:27 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,923
Blog Entries: 1

Rep: Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885Reputation: 1885
Guess you mean you wish to use `libmagic` or `file` utility in your program.
 
Old 07-04-2024, 04:16 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,706

Rep: Reputation: Disabled
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.
Old 07-04-2024, 04:09 PM   #4
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,639

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
I am using ruby-filemagic.
It looks as if I have not understood ARGF.filename, nor ARGF.read.
TY.
 
Old 07-05-2024, 04:17 PM   #5
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,639

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
Good evening

FileMagic.mime.buffer is not documented, it seems.
But I am using it now.
 
Old 07-06-2024, 06:26 AM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,706

Rep: Reputation: Disabled
It is a shortcut for FileMagic.open(:mime).buffer as described here.
 
Old 07-07-2024, 02:28 PM   #7
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,639

Original Poster
Blog Entries: 40

Rep: Reputation: Disabled
Maybe I am able to understand Ruby and some Modules, but unable to cope with the documentation.
 
  


Reply

Tags
ruby, ruby filemagic stdin


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Ruby / Gem] Too tired for rant. Again. Confused filemagic and ruby-filemagic Michael Uplawski Programming 2 03-12-2022 03:57 AM
[SOLVED] [Ruby] Cannot read from STDIN after piping-in a file Michael Uplawski Programming 12 08-29-2016 10:55 AM
Ruby SDL/ Ruby OpenGL tutorials/reference? LinuxNoob75 Programming 0 12-30-2007 12:47 PM
PHP v Ruby/Ruby on Rails Neko_D Linux - General 4 02-08-2007 11:56 PM
[Ruby] Tar'ing or Zip'ing with ruby script lmcilwain Programming 2 01-19-2007 06:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration