Module: Ronin::Support::Archive::Tar
- Defined in:
- lib/ronin/support/archive/tar.rb,
lib/ronin/support/archive/tar/reader.rb,
lib/ronin/support/archive/tar/writer.rb
Overview
Handles tar archive reading/writing.
Examples
Create a tar reader stream around an existing IO object:
Tar.new(io) do |tar|
file = tar['file.txt']
puts "#{file.full_name} (#{file.header.umode})"
puts file.read
end
Opening a tar writer stream around an existing IO object:
Tar.new(io, mode: 'w') do |tar|
# add a file
tar.add_file('file1.txt', "...")
# add a file and open an output stream
tar.add_file('file2.txt') do |io|
io.write("...")
end
# add a symlink 'link' pointing to 'file1.txt'
tar.add_symlink('link','file1.txt')
# add a directory
tar.mkdir('foo')
end
Opening
Defined Under Namespace
Class Method Summary collapse
-
.new(io, mode: 'r') {|tar| ... } ⇒ Reader, Writer
Creates a tar stream around the IO object.
-
.open(path, mode: 'r') {|gz| ... } ⇒ Reader, Writer
Opens the tar file for reading or writing.
Class Method Details
.new(io, mode: 'r') {|tar| ... } ⇒ Reader, Writer
Creates a tar stream around the IO object.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ronin/support/archive/tar.rb', line 96 def self.new(io, mode: 'r', &block) tar_class = if mode.include?('w') || mode.include?('a') Writer elsif mode.include?('r') Reader else raise(ArgumentError,"mode argument must include either 'r', 'w', or 'a': #{mode.inspect}") end return tar_class.new(io, mode: mode, &block) end |
.open(path, mode: 'r') {|gz| ... } ⇒ Reader, Writer
Opens the tar file for reading or writing.
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ronin/support/archive/tar.rb', line 141 def self.open(path, mode: 'r', &block) tar_class = if mode.include?('w') || mode.include?('a') Writer elsif mode.include?('r') Reader else raise(ArgumentError,"mode argument must include either 'r', 'w', or 'a': #{mode.inspect}") end return tar_class.open(path,&block) end |