Class: Ronin::Support::Archive::Zip::Reader
- Inherits:
-
Object
- Object
- Ronin::Support::Archive::Zip::Reader
- Includes:
- Enumerable
- Defined in:
- lib/ronin/support/archive/zip/reader.rb,
lib/ronin/support/archive/zip/reader/entry.rb,
lib/ronin/support/archive/zip/reader/statistics.rb
Overview
This provides a simple interface for reading zip archives using
the unzip
command. If you need something more powerful, use the
[archive-zip] gem instead.
Handles reading zip archives.
Defined Under Namespace
Classes: Entry, Statistics
Instance Attribute Summary collapse
-
#password ⇒ String?
readonly
The optional password to use when reading the zip archive.
-
#path ⇒ String
readonly
The path to the zip archive that will be read.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](name) ⇒ Entry?
Finds the entry with the given name.
-
#each {|entry| ... } ⇒ Enumerator, Statistics
(also: #list)
Lists the contents of the zip archive.
-
#initialize(path, password: nil) {|zip| ... } ⇒ Reader
constructor
Initializes the zip archive reader.
-
#read(name, length: nil) ⇒ String
Reads the contents of an entry from the zip archive.
Methods included from Enumerable
Constructor Details
Instance Attribute Details
#password ⇒ String? (readonly)
The optional password to use when reading the zip archive.
54 55 56 |
# File 'lib/ronin/support/archive/zip/reader.rb', line 54 def password @password end |
#path ⇒ String (readonly)
The path to the zip archive that will be read.
49 50 51 |
# File 'lib/ronin/support/archive/zip/reader.rb', line 49 def path @path end |
Class Method Details
.open(path, **kwargs) {|zip| ... } ⇒ Object
Alias to new.
98 99 100 |
# File 'lib/ronin/support/archive/zip/reader.rb', line 98 def self.open(path,**kwargs,&block) new(path,**kwargs,&block) end |
Instance Method Details
#[](name) ⇒ Entry?
Finds the entry with the given name.
157 158 159 |
# File 'lib/ronin/support/archive/zip/reader.rb', line 157 def [](name) find { |entry| entry.name == name } end |
#each {|entry| ... } ⇒ Enumerator, Statistics Also known as: list
This method actually executes the unzip -v -l ZIP
command
and parses it's output.
Lists the contents of the zip archive.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ronin/support/archive/zip/reader.rb', line 120 def each return enum_for(__method__) unless block_given? io = IO.popen(command_argv('-v','-l',@path)) # skip lines until the "--------- ---------- ----- ----" line until io.eof? break if io.readline.start_with?('-') end until io.eof? line = io.readline(chomp: true) unless line.start_with?('-') yield parse_entry_line(line) else # reached the "--------- -------" line break end end last_line = io.readline(chomp: true) return parse_statistics_line(last_line) end |
#read(name, length: nil) ⇒ String
This method actually executes the unzip -p ZIP FILE
command
and reads it's output.
Reads the contents of an entry from the zip archive.
177 178 179 180 181 182 183 |
# File 'lib/ronin/support/archive/zip/reader.rb', line 177 def read(name, length: nil) io = IO.popen(command_argv('-p', @path, name)) if length then io.read(length) else io.read end end |