Class: Archive::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/libarchive_rs.rb

Instance Method Summary collapse

Instance Method Details

#read_data(size = nil) ⇒ Object

Reads size bytes from the Archive. If a block is given, chunks of size bytes are repeatedly passed to the block until the complete data stored for the Entry has been read. If size is not specified, all data stored is returned at once.


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/libarchive_rs.rb', line 92

def read_data(size = nil)
  if block_given?
    if size.nil?
      result = []
      while data = self.read_data_helper(1024)
        result << data
      end
      yield result.join('')
    else
      while data = self.read_data_helper(size)
        yield data
      end
    end
  else
    if size.nil?
      result = []
      while data = self.read_data_helper(1024)
        result << data
      end
      return result.join('')
    else
      return self.read_data_helper(size)
    end
  end
end