Class: Omnizip::Formats::Ole::RangesIOResizeable
- Defined in:
- lib/omnizip/formats/ole/ranges_io.rb
Overview
Resizeable RangesIO backed by AllocationTable
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bat ⇒ AllocationTable
readonly
Backing allocation table.
-
#first_block ⇒ Integer
First block index.
Attributes inherited from RangesIO
Instance Method Summary collapse
-
#free ⇒ void
Free resources to prevent memory leaks.
-
#initialize(bat, first_block:, size: nil) ⇒ RangesIOResizeable
constructor
Initialize resizeable RangesIO.
-
#truncate(new_size) ⇒ Object
Truncate to new size.
Methods inherited from RangesIO
#close, #eof?, #inspect, open, #read, #rewind, #write
Constructor Details
#initialize(bat, first_block:, size: nil) ⇒ RangesIOResizeable
Initialize resizeable RangesIO
253 254 255 256 257 258 259 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 253 def initialize(bat, first_block:, size: nil) @bat = bat @first_block = first_block @blocks = first_block == Constants::EOC ? [] : bat.chain(first_block) super(bat.io, bat.ranges(@blocks, size)) end |
Instance Attribute Details
#bat ⇒ AllocationTable (readonly)
Returns Backing allocation table.
243 244 245 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 243 def bat @bat end |
#first_block ⇒ Integer
Returns First block index.
246 247 248 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 246 def first_block @first_block end |
Instance Method Details
#free ⇒ void
This method returns an undefined value.
Free resources to prevent memory leaks
278 279 280 281 282 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 278 def free @bat = nil @blocks = nil super end |
#truncate(new_size) ⇒ Object
Truncate to new size
264 265 266 267 268 269 270 271 272 273 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 264 def truncate(new_size) @bat.resize_chain(@blocks, new_size) @pos = new_size if @pos > new_size self.ranges = @bat.ranges(@blocks, new_size) @first_block = @blocks.empty? ? Constants::EOC : @blocks.first # Grow underlying IO if needed max_pos = @ranges.map { |pos, len| pos + len }.max || 0 @io.truncate(max_pos) if max_pos > @io.size end |