Class: Cabriolet::CAB::Extractor::BlockReader

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_blockObject (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_dataObject (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_systemObject (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_blocksObject (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

#salvageObject (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

#closeObject



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

#tellObject



217
218
219
# File 'lib/cabriolet/cab/extractor.rb', line 217

def tell
  0
end