Easy way that compress files in ruby is using zip lib. Zip :: File . open ( './compress.zip' , create: true ) do | zip | zip . get_output_stream ( "./stuff_to_ziped.pdf" ) do | f | f . puts File . read ( "./stuff_to_zip.pdf" ) end end When you need to zip larger files or when you need to perform any task that requires opening many files, good practice is to avoid loading all files into memory. To achieve this, you can use stream operations available in IO classes. Let's look at the code above ag

How you zip larger files in ruby
luiz filipe neves
