From: Michal Suchanek Date: 2008-01-04T23:24:09+09:00 Subject: Re: Get your hands dirty: Help bootstrap Ruby on Windows. On 04/01/2008, Luis Lavena wrote: > On 4 ene, 09:35, Michal Suchanek wrote: > > > > If youcan afford relying on ruby stdlib, there is zlib which can do > > deflate and gunzip. > > > > There is minitar hosted on rubyforge under ruwiki (does not work on > > unseekable files like stdin but works on gzipped files by using zlib). > > There is rubyzip (untested, uses zlib for compression). bzip2 remains > > to be solved but hopefully the basic stuff can be obtained as gzipped > > archives. > > > > http://rubyforge.org/frs/?group_id=84 > > http://rubyforge.org/frs/?group_id=909 > > > > Thank you Michal, > > Since I was moving from a batch-build process to a ruby/rake build > process, a few external tools remains as requirement. > > MinGW packages are distributed in tar.gz format [1] (which I guess map > perfect for Minitar project), but MSYS provides tar.bz2 files [2], > which will still need the external tool to uncompress. > > In this case, tar.bz2 files can be uncompressed with bsdtar, which is > the best implementation I've tested that work with all the file > formats. (tgz, tar.gz and tar.bz2) > > There is also the memory usage and speed situation, extract 8MB files > can take a bit slow using a pure-ruby implementation. The decompression is handled by zlib so this should not be that much of an issue. Still people extracting on slow machines could see the difference, and there should be no problem with including these unpack tools in the archive containing the build scripts. On the other hand, the minitar might be useful if you wanted to do something special with symlinks (currently it does not extract them at all). Maintaining a patched minitar might be easier than maintaining a patched bsdtar binary. The rubyzip implementation does not include a working command line tool as far as I can tell. A poor man's unzip using the library is simple but I am not sure it is of much use. Perhaps an external unzip tool would be easier. Thanks Michal #unzip.rb # The example: #Zip::ZipInputStream::open("my.zip") { # |io| # # while (entry = io.get_next_entry) # puts "Contents of #{entry.name}: '#{io.read}'" # end # } require 'zip/zip' def open_wr fn elts = fn.split("/") dir = "" elts[0...-1].each{|d| raise RuntimeError, "Invalid filename '#{fn}'." if d == "" or d == ".." dir << d << "/" Dir.mkdir dir unless File.directory? dir } raise RuntimeError, "File exists '#{fn}'." if File.exist? fn File.open(fn,"wb"){|f| yield f} end Zip::ZipInputStream::open(ARGV[0]) { |io| while (entry = io.get_next_entry) STDERR.puts entry.name # directories are of type file, they just have a trailing slash next if entry.name[-1] == '/'[-1] open_wr(entry.name){|out| out << io.read} end }