Class: Cabriolet::CAB::Extractor::BlockReader
- Inherits:
-
Object
- Object
- Cabriolet::CAB::Extractor::BlockReader
- Defined in:
- lib/cabriolet/cab/extractor.rb
Overview
BlockReader wraps cabinet file handles and reads CFDATA blocks Handles multi-part cabinets by following the FolderData chain
Instance Attribute Summary collapse
-
#current_block ⇒ Object
readonly
Returns the value of attribute current_block.
-
#current_data ⇒ Object
readonly
Returns the value of attribute current_data.
-
#io_system ⇒ Object
readonly
Returns the value of attribute io_system.
-
#num_blocks ⇒ Object
readonly
Returns the value of attribute num_blocks.
-
#salvage ⇒ Object
readonly
Returns the value of attribute salvage.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(io_system, folder_data, num_blocks, salvage) ⇒ BlockReader
constructor
A new instance of BlockReader.
- #read(bytes) ⇒ Object
- #seek(_offset, _whence) ⇒ Object
- #tell ⇒ Object
Constructor Details
#initialize(io_system, folder_data, num_blocks, salvage) ⇒ BlockReader
Returns a new instance of BlockReader.
180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/cabriolet/cab/extractor.rb', line 180 def initialize(io_system, folder_data, num_blocks, salvage) @io_system = io_system @current_data = folder_data @num_blocks = num_blocks @salvage = salvage @current_block = 0 @buffer = "" @buffer_pos = 0 @cab_handle = nil # Open first cabinet and seek to data offset open_current_cabinet end |
Instance Attribute Details
#current_block ⇒ Object (readonly)
Returns the value of attribute current_block.
177 178 179 |
# File 'lib/cabriolet/cab/extractor.rb', line 177 def current_block @current_block end |
#current_data ⇒ Object (readonly)
Returns the value of attribute current_data.
177 178 179 |
# File 'lib/cabriolet/cab/extractor.rb', line 177 def current_data @current_data end |
#io_system ⇒ Object (readonly)
Returns the value of attribute io_system.
177 178 179 |
# File 'lib/cabriolet/cab/extractor.rb', line 177 def io_system @io_system end |
#num_blocks ⇒ Object (readonly)
Returns the value of attribute num_blocks.
177 178 179 |
# File 'lib/cabriolet/cab/extractor.rb', line 177 def num_blocks @num_blocks end |
#salvage ⇒ Object (readonly)
Returns the value of attribute salvage.
177 178 179 |
# File 'lib/cabriolet/cab/extractor.rb', line 177 def salvage @salvage end |
Instance Method Details
#close ⇒ Object
221 222 223 224 |
# File 'lib/cabriolet/cab/extractor.rb', line 221 def close @cab_handle&.close @cab_handle = nil end |
#read(bytes) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/cabriolet/cab/extractor.rb', line 194 def read(bytes) result = +"" while result.bytesize < bytes # Read more data if buffer is empty break if (@buffer_pos >= @buffer.bytesize) && !read_next_block # Copy from buffer available = @buffer.bytesize - @buffer_pos to_copy = [available, bytes - result.bytesize].min result << @buffer[@buffer_pos, to_copy] @buffer_pos += to_copy end result end |
#seek(_offset, _whence) ⇒ Object
212 213 214 215 |
# File 'lib/cabriolet/cab/extractor.rb', line 212 def seek(_offset, _whence) # Not implemented for block reader 0 end |
#tell ⇒ Object
217 218 219 |
# File 'lib/cabriolet/cab/extractor.rb', line 217 def tell 0 end |