Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Is it possible to compress a directory with the standard Ruby library

compress directory

  • Please log in to reply
4 replies to this topic

#1 samz

samz

    Passenger

  • Members
  • 2 posts
  • LocationSwitzerland

Posted 06 September 2013 - 04:14 PM

Hello,

 

Is it possible to compress a directory with the standard Ruby library?

If yes, can you give a simple example script.

 

http://www.ruby-doc.org/stdlib-2.0.0/

 

Thanks and regards.



#2 Ohm

Ohm

    Guard

  • Members
  • 186 posts
  • LocationCopenhagen

Posted 07 September 2013 - 03:01 PM

What exactly do you mean by "compress"? Are you looking for a method to do size compression on folders?


Blog: http://ohm.sh | Twitter: madsohm


#3 samz

samz

    Passenger

  • Members
  • 2 posts
  • LocationSwitzerland

Posted 08 September 2013 - 08:49 PM

I mean compact (reduce the size) of an entire folder in 1 file (.zip or .tar or any other Android compatible format).

Googleling I found some solutions but (I think) they all use external library.

And the standard Ruby library "zlib" can compress only files, not an entire folder :(

 

Context:

I would like to write a Ruby script runing on my Android smartphone (using Ruboto) to backup/restore some apps' settings:

- copy some apps' settings into a folder.

- Zip (compress) this folder.

- Send the zip file to an FTP server.

 

Thanks and regards.



#4 Ohm

Ohm

    Guard

  • Members
  • 186 posts
  • LocationCopenhagen

Posted 08 September 2013 - 09:08 PM

The only way I can imagine this right now, is to somehow tar your files together and the using zlib to compress the one tar-file.

 

However I can't think of a way of doing this, that would be readable on the server as there doesn't seem to be a stdlib method for tar'ing files together.

 

You could just read through the folder, concating everything into one string with a self made delimiter and then compressing it, sending it via FTP and then on the server uncompress it and do the reverse, splitting it by the delimiter.


Blog: http://ohm.sh | Twitter: madsohm


#5 katafrakt

katafrakt

    Signalman

  • Members
  • 16 posts
  • LocationKrak√≥w, PL

Posted 12 September 2013 - 07:20 AM

Why limit only to stdlib when you have https://github.com/rubyzip/rubyzip which does exactly what you want? ;)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users