Class: VirtDisk::ClientHead
- Inherits:
-
Object
- Object
- VirtDisk::ClientHead
- Includes:
- ExportMethods
- Defined in:
- lib/virt_disk/client_head.rb
Instance Attribute Summary collapse
-
#end_byte_addr ⇒ Object
readonly
Returns the value of attribute end_byte_addr.
-
#seek_pos ⇒ Object
readonly
Returns the value of attribute seek_pos.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#start_byte_addr ⇒ Object
readonly
Returns the value of attribute start_byte_addr.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(up_stream_module) ⇒ ClientHead
constructor
A new instance of ClientHead.
- #mod_read(offset, len) ⇒ Object
- #mod_write(offset, buffer, len) ⇒ Object
- #read(len) ⇒ Object
- #seek(amt, whence = IO::SEEK_SET) ⇒ Object
- #write(buf, len) ⇒ Object
Methods included from ExportMethods
#delegate, #delegate=, #exported?, included, #method_missing, #respond_to_missing?
Constructor Details
#initialize(up_stream_module) ⇒ ClientHead
Returns a new instance of ClientHead.
7 8 9 10 11 12 13 14 |
# File 'lib/virt_disk/client_head.rb', line 7 def initialize(up_stream_module) @up_stream_module = up_stream_module @start_byte_addr = 0 @size = @up_stream_module.size @end_byte_addr = @size - 1 @seek_pos = @start_byte_addr self.delegate = @up_stream_module end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class VirtDisk::ExportMethods
Instance Attribute Details
#end_byte_addr ⇒ Object (readonly)
Returns the value of attribute end_byte_addr.
3 4 5 |
# File 'lib/virt_disk/client_head.rb', line 3 def end_byte_addr @end_byte_addr end |
#seek_pos ⇒ Object (readonly)
Returns the value of attribute seek_pos.
3 4 5 |
# File 'lib/virt_disk/client_head.rb', line 3 def seek_pos @seek_pos end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/virt_disk/client_head.rb', line 3 def size @size end |
#start_byte_addr ⇒ Object (readonly)
Returns the value of attribute start_byte_addr.
3 4 5 |
# File 'lib/virt_disk/client_head.rb', line 3 def start_byte_addr @start_byte_addr end |
Instance Method Details
#close ⇒ Object
16 17 18 |
# File 'lib/virt_disk/client_head.rb', line 16 def close @up_stream_module.close end |
#mod_read(offset, len) ⇒ Object
48 49 50 |
# File 'lib/virt_disk/client_head.rb', line 48 def mod_read(offset, len) @up_stream_module.mod_read(offset, len) end |
#mod_write(offset, buffer, len) ⇒ Object
52 53 54 |
# File 'lib/virt_disk/client_head.rb', line 52 def mod_write(offset, buffer, len) @up_stream_module.mod_write(offset, buffer, len) end |
#read(len) ⇒ Object
36 37 38 39 40 |
# File 'lib/virt_disk/client_head.rb', line 36 def read(len) rb = mod_read(@seek_pos, len) @seek_pos += rb.length unless rb.nil? rb end |
#seek(amt, whence = IO::SEEK_SET) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/virt_disk/client_head.rb', line 24 def seek(amt, whence = IO::SEEK_SET) case whence when IO::SEEK_CUR @seek_pos += amt when IO::SEEK_END @seek_pos = @endByteAddr + amt when IO::SEEK_SET @seek_pos = amt + @start_byte_addr end @seek_pos end |
#write(buf, len) ⇒ Object
42 43 44 45 46 |
# File 'lib/virt_disk/client_head.rb', line 42 def write(buf, len) nbytes = @up_stream_module.mod_write(@seek_pos, buf, len) @seek_pos += nbytes nbytes end |