Class: VirtDisk::FileIo
- Inherits:
-
Object
- Object
- VirtDisk::FileIo
- Includes:
- LogDecorator::Logging, ExportMethods
- Defined in:
- lib/virt_disk/file_io.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
(also: #file_name)
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path, *args) ⇒ FileIo
constructor
A new instance of FileIo.
- #mod_read(start, len) ⇒ Object
- #mod_write(buf, start, len) ⇒ Object
- #size ⇒ Object
Methods included from ExportMethods
#delegate, #delegate=, #exported?, included, #method_missing, #respond_to_missing?
Constructor Details
#initialize(path, *args) ⇒ FileIo
Returns a new instance of FileIo.
11 12 13 14 15 16 17 |
# File 'lib/virt_disk/file_io.rb', line 11 def initialize(path, *args) @path = path @file_lock = Mutex.new _log.debug "Opening file - #{path}" @file = File.open(path, *args) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class VirtDisk::ExportMethods
Instance Attribute Details
#path ⇒ Object Also known as: file_name
Returns the value of attribute path.
3 4 5 |
# File 'lib/virt_disk/file_io.rb', line 3 def path @path end |
Instance Method Details
#close ⇒ Object
24 25 26 |
# File 'lib/virt_disk/file_io.rb', line 24 def close @file.close end |
#mod_read(start, len) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/virt_disk/file_io.rb', line 28 def mod_read(start, len) @file_lock.synchronize do @file.seek start @file.read len end end |
#mod_write(buf, start, len) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/virt_disk/file_io.rb', line 35 def mod_write(buf, start, len) @file_lock.synchronize do @file.seek start @file.write buf, len end end |
#size ⇒ Object
19 20 21 |
# File 'lib/virt_disk/file_io.rb', line 19 def size @file.size end |