Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract a .rar archive with Ruby?

Tags:

ruby

I need to unpack an .rar archive with Ruby. I could not find a gem though.
I discovered the rar gem which only allows to create an archive. How can I extract a rar file, not just create it?

like image 803
JJD Avatar asked Apr 20 '15 18:04

JJD


People also ask

Is it safe to extract RAR files?

RAR files are safe in themselves. Like zip files, their purpose is to have other files. But it is worth noting that the files present in the RAR file can be dangerous. In fact, cybercriminals usually spread malware through archived files such as RAR files.


2 Answers

After doing some additional reading on the subject it seems that any gems that were for this are basically abandoned. But, you can brew install unrar and use that from Ruby system('unrar l your_file.rar').

like image 88
Chase Avatar answered Oct 02 '22 02:10

Chase


ffi-libarchive provides a gem-based solution. It works for rar files even though they don't specifically mention it (see issue #151). Add this to your application's Gemfile:

gem 'ffi-libarchive'

and then execute:

$ bundle
like image 24
TamaMcGlinn Avatar answered Oct 02 '22 01:10

TamaMcGlinn