Class: Ole::Storage::RangesIOMigrateable
- Inherits:
-
RangesIOResizeable
- Object
- RangesIO
- RangesIOResizeable
- Ole::Storage::RangesIOMigrateable
- Defined in:
- lib/ole/storage.rb
Overview
like RangesIOResizeable, but Ole::Storage::Dirent specific. provides for migration between bats based on size, and updating the dirent.
Instance Attribute Summary collapse
-
#dirent ⇒ Object
readonly
Returns the value of attribute dirent.
Attributes inherited from RangesIOResizeable
Attributes inherited from RangesIO
#io, #mode, #pos, #ranges, #size
Instance Method Summary collapse
-
#first_block ⇒ Object
forward this to the dirent.
- #first_block=(val) ⇒ Object
-
#initialize(dirent, mode = 'r') ⇒ RangesIOMigrateable
constructor
A new instance of RangesIOMigrateable.
- #truncate(size) ⇒ Object
Methods inherited from RangesIO
#close, #eof?, #gets, #inspect, #offset_and_size, open, #read, #write
Constructor Details
#initialize(dirent, mode = 'r') ⇒ RangesIOMigrateable
Returns a new instance of RangesIOMigrateable.
657 658 659 660 661 |
# File 'lib/ole/storage.rb', line 657 def initialize dirent, mode='r' @dirent = dirent super @dirent.ole.bat_for_size(@dirent.size), mode, :first_block => @dirent.first_block, :size => @dirent.size end |
Instance Attribute Details
#dirent ⇒ Object (readonly)
Returns the value of attribute dirent.
656 657 658 |
# File 'lib/ole/storage.rb', line 656 def dirent @dirent end |
Instance Method Details
#first_block ⇒ Object
forward this to the dirent
692 693 694 |
# File 'lib/ole/storage.rb', line 692 def first_block @dirent.first_block end |
#first_block=(val) ⇒ Object
696 697 698 |
# File 'lib/ole/storage.rb', line 696 def first_block= val @dirent.first_block = val end |
#truncate(size) ⇒ Object
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'lib/ole/storage.rb', line 663 def truncate size bat = @dirent.ole.bat_for_size size if bat.class != @bat.class # bat migration needed! we need to backup some data. the amount of data # should be <= @ole.header.threshold, so we can just hold it all in one buffer. # backup this pos = @pos @pos = 0 keep = read [@size, size].min # this does a normal truncate to 0, removing our presence from the old bat, and # rewrite the dirent's first_block super 0 @bat = bat # just change the underlying io from right under everyone :) @io = bat.io # important to do this now, before the write. as the below write will always # migrate us back to sbat! this will now allocate us +size+ in the new bat. super @pos = 0 write keep @pos = pos else super end # now just update the file @dirent.size = size end |