minitar.rb

Path: lib/more/facets/minitar.rb
Last Update: Tue Oct 28 06:39:06 -0400 2008

Archive::Tar::Minitar

Synopsis

Archive::Tar::Minitar is a pure-Ruby library and command-line utility that provides the ability to deal with POSIX tar(1) archive files. The implementation is based heavily on Mauricio Fern�dez‘s implementation in rpa-base, but has been reorganised to promote reuse in other projects.

This tar class performs a subset of all tar (POSIX tape archive) operations. We can only deal with typeflags 0, 1, 2, and 5 (see Archive::Tar::PosixHeader). All other typeflags will be treated as normal files.

NOTE::support for typeflags 1 and 2 is not yet implemented in this version.

This release is version 0.5.1. The library can only handle files and directories at this point. A future version will be expanded to handle symbolic links and hard links in a portable manner. The command line utility, minitar, can only create archives, extract from archives, and list archive contents.

Synopsis

Using this library is easy. The simplest case is:

  require 'zlib'
  require 'archive/tar/minitar'
  include Archive::Tar

    # Packs everything that matches Find.find('tests')
  File.open('test.tar', 'wb') { |tar| Minitar.pack('tests', tar) }
    # Unpacks 'test.tar' to 'x', creating 'x' if necessary.
  Minitar.unpack('test.tar', 'x')

A gzipped tar can be written with:

  tgz = Zlib::GzipWriter.new(File.open('test.tgz', 'wb'))
    # Warning: tgz will be closed!
  Minitar.pack('tests', tgz)

  tgz = Zlib::GzipReader.new(File.open('test.tgz', 'rb'))
    # Warning: tgz will be closed!
  Minitar.unpack(tgz, 'x')

As the case above shows, one need not write to a file. However, it will sometimes require that one dive a little deeper into the API, as in the case of StringIO objects. Note that I‘m not providing a block with Minitar::Output, as Minitar::Output#close automatically closes both the Output object and the wrapped data stream object.

  begin
    sgz = Zlib::GzipWriter.new(StringIO.new(""))
    tar = Output.new(sgz)
    Find.find('tests') do |entry|
      Minitar.pack_file(entry, tar)
    end
  ensure
      # Closes both tar and sgz.
    tar.close
  end

Version

  0.5.1

Authors

  • Mauricio Julio Fern�dez Pradier
  • Austin Ziegler

Copying

Copyright 2004 Mauricio Julio Fern�dez Pradier and Austin Ziegler

This program is based on and incorporates parts of RPA::Package from rpa-base (lib/rpa/package.rb and lib/rpa/util.rb) by Mauricio and has been adapted to be more generic by Austin.

‘minitar’ contains an adaptation of Ruby/ProgressBar by Satoru Takabayashi <satoru@namazu.org>, copyright 2001 - 2004.

This program is free software. It may be redistributed and/or modified under the terms of the GPL version 2 (or later) or Ruby‘s licence.

Required files

fileutils   find  

[Validate]