Class: Omnizip::Formats::Ole::RangesIOMigrateable
- Inherits:
-
RangesIOResizeable
- Object
- RangesIO
- RangesIOResizeable
- Omnizip::Formats::Ole::RangesIOMigrateable
- Defined in:
- lib/omnizip/formats/ole/ranges_io.rb
Overview
RangesIO that can migrate between BAT and SBAT based on size
Instance Attribute Summary collapse
-
#dirent ⇒ Dirent
readonly
Associated dirent.
Attributes inherited from RangesIOResizeable
Attributes inherited from RangesIO
Instance Method Summary collapse
-
#first_block ⇒ Object
Forward first_block to dirent (for reading).
- #first_block=(val) ⇒ Object
-
#initialize(dirent, mode = "r") ⇒ RangesIOMigrateable
constructor
Initialize migrateable RangesIO.
-
#truncate(new_size) ⇒ Object
Truncate with BAT migration support.
-
#writeable? ⇒ Boolean
Check if writable.
Methods inherited from RangesIOResizeable
Methods inherited from RangesIO
#close, #eof?, #free, #inspect, open, #read, #rewind, #write
Constructor Details
#initialize(dirent, mode = "r") ⇒ RangesIOMigrateable
Initialize migrateable RangesIO
294 295 296 297 298 299 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 294 def initialize(dirent, mode = "r") @dirent = dirent bat = dirent.ole.bat_for_size(dirent.size) super(bat, first_block: dirent.first_block, size: dirent.size) @mode = mode end |
Instance Attribute Details
#dirent ⇒ Dirent (readonly)
Returns Associated dirent.
288 289 290 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 288 def dirent @dirent end |
Instance Method Details
#first_block ⇒ Object
Forward first_block to dirent (for reading)
336 337 338 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 336 def first_block @first_block end |
#first_block=(val) ⇒ Object
340 341 342 343 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 340 def first_block=(val) @first_block = val @dirent.first_block = val end |
#truncate(new_size) ⇒ Object
Truncate with BAT migration support
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 309 def truncate(new_size) new_bat = @dirent.ole.bat_for_size(new_size) if new_bat.instance_of?(@bat.class) super else # BAT migration needed pos = [@pos, new_size].min self.pos = 0 keep = read([@size, new_size].min) super(0) @bat = new_bat @io = new_bat.io super self.pos = 0 write(keep) self.pos = pos end # Update dirent's first_block and size after any resize @dirent.first_block = @first_block @dirent.size = new_size end |
#writeable? ⇒ Boolean
Check if writable
302 303 304 |
# File 'lib/omnizip/formats/ole/ranges_io.rb', line 302 def writeable? @mode.include?("w") || @mode.include?("a") || @mode.include?("+") end |