I want do unzip a lot of zip files, is there a module or script that check which format the zip file is and decompress it? this should work on linux, other OSs I don't care for this.
+3
A:
libarchive appears to provide everything you ask for. It currently (2010-04-13) provides the following functionality:
Reading
- gzip compression
- bzip2 compression
- compress/LZW compression
- GNU tar format (including GNU long filenames, long link names, and sparse files)
- Solaris 9 extended tar format (including ACLs)
- Old V7 tar archives
- POSIX ustar
- POSIX pax interchange format
- POSIX octet-oriented cpio
- SVR4 ASCII cpio
- Binary cpio (big-endian or little-endian)
- ISO9660 CD-ROM images (with optional Rockridge extensions)
- ZIP archives (with uncompressed or "deflate" compressed entries)
- GNU and BSD ‘ar’ archives
- ‘mtree’ format (lzma compression not supported)
Writing
- gzip compression
- bzip2 compression
- compress/LZW compression
- POSIX ustar
- POSIX pax interchange format
- "restricted" pax format, which will create ustar archives except for entries that require pax extensions (for long filenames, etc). (ACLs not supported.)
- POSIX octet-oriented cpio
- SVR4 "newc" cpio
- shar archives
- GNU and BSD ‘ar’ archives
(A previous version of this answer suggested using Facets, but that project no longer provides ziputils.rb
.)
Stephan202
2009-05-13 09:23:04
This is apparently no longer part of facets...
Luke Bayes
2010-04-13 04:50:03
@Luke: well spotted! I cannot delete this answer (because it's accepted), so I went looking for an alternative. I have replaced it with completely new info. Hope that helps :)
Stephan202
2010-04-13 18:42:11
Turns this is a Ruby wrapper for a native library that doesn't seem to install on my OS X system, and doesn't have any information other than the rdocs. I recognize that the original question was only directed at linux, but thought others would want to know.
Luke Bayes
2010-04-15 02:17:07
+2
A:
The easiest way is to probably use Zlib
Zlib is a Ruby library. What follows is a simple program to grab a Zipped file from a particular URL, unzip it, and paste its contents to the screen.
require 'zlib'
require 'open-uri'
@uri = "www.somedomain.com/filename.gz"
@source = open(uri)
@gz = Zlib::GzipReader.new(@source)
@result = @gz.read
puts @result
I hope this helps.
Mavryx
2010-01-06 16:13:46