Class: Ronin::Support::Archive::Tar::Reader

Inherits:
Gem::Package::TarReader
  • Object
show all
Defined in:
lib/ronin/support/archive/tar/reader.rb

Overview

Handling reading tar encoded archive data.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(io_or_buffer, mode: 'r') {|tar| ... } ⇒ Reader

Initializes the tar writer.

Examples:

Initializing with an IO object:

tar = Archive::Tar::Reader.new(io)

Initializing with a buffer:

buffer = "..."
tar   = Archive::Tar::Reader.new(buffer)

Yields:

  • (tar)

    If a block is given, it will be passed the new tar reader object.

Yield Parameters:

  • tar (Reader)

    The tar reader object.

Since:

  • 1.0.0



65
66
67
68
69
70
71
72
# File 'lib/ronin/support/archive/tar/reader.rb', line 65

def self.new(io_or_buffer, mode: 'r', &block)
  io = case io_or_buffer
       when String then StringIO.new(io_or_buffer,mode)
       else             io_or_buffer
       end

  return super(io,&block)
end

.open(path) {|tar| ... } ⇒ Reader

Opens the tar archive file for reading.

Yields:

  • (tar)

    If a block is given, then it will be passed the new tar reader object.

Yield Parameters:

  • tar (Reader)

    The newly created tar reader object.

Since:

  • 1.0.0



90
91
92
93
94
95
96
97
98
# File 'lib/ronin/support/archive/tar/reader.rb', line 90

def self.open(path,&block)
  if block
    File.open(path,'rb') do |file|
      new(file,&block)
    end
  else
    new(File.new(path,'rb'))
  end
end

Instance Method Details

#[](name) ⇒ Entry?

Finds an entry in the tar archive with the matching name.

Since:

  • 1.0.0



109
110
111
# File 'lib/ronin/support/archive/tar/reader.rb', line 109

def [](name)
  find { |entry| entry.full_name == name }
end

#read(name, length: nil) ⇒ String

Reads the contents of an entry from the tar archive.

Since:

  • 1.0.0



125
126
127
128
129
# File 'lib/ronin/support/archive/tar/reader.rb', line 125

def read(name, length: nil)
  if (entry = self[name])
    entry.read(length)
  end
end