Module TapeArchive |
|
TapeArchive is a module that allows Ruby programs to create and access ‘tar’ files, natively. It depends on no external utilities (ie, the ‘tar’ program), so you can use it on systems where ‘tar’ is not normally installed.
To use it to list all entries in a tar file:
require 'tar' TapeArchive::File.open( "some.tar" ) do |file| file.each_entry do |entry| puts "#{entry.name} :: #{entry.size} bytes" end end
To actually extract the contents of each entry in a tar file:
TapeArchive::File.open( "some.tar" ) do |file| file.each_entry do |entry| content = entry.contents end end
Alternatively, you can get an InputStream for each entry by calling entry.get_input_stream.
To create a new tar file:
TapeArchive::File.create( "some-new.tar" ) do |file| file.new_entry "somefile.txt" file.puts "text" file.new_entry "anotherfile.txt" file.puts "more text" end
To append to the end of an existing tar file (or create a new file):
TapeArchive::File.append( "some-old.tar" ) do |file| file.new_entry "appended-file.txt" file.puts "text" end
Classes and Modules |