Creating and Extracting a tgz archive in Rails
Does anyone know how to archive a folder and its contained files as a tgz archive using Rails? Wh开发者_高级运维at I would like todo is archive the contents of the folder and then have another script which extracts the same folder that was archived.
All of the archiving techniques that I've come across are pretty complicated, I was wondering if there is a simple solution to what I am looking for.
If you server is *nix, the simplest solution is to leverage Ruby's OS integration and call GNU tar using backquotes.
To create an archive:
`tar cvzf #{archive_file_name}.tar.gz #{dir_to_be_archived}`
To unpack it:
`tar zxvf #{archive_file_name}.tar.gz`
There is the Minitar library. It works with ruby in general and archiving and unarchiving is as simple as Minitar.pack
and Minitar.unpack
.
精彩评论