Class: VirtDisk::FileIo

Inherits:
Object
  • Object
show all
Includes:
LogDecorator::Logging, ExportMethods
Defined in:
lib/virt_disk/file_io.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject 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

#closeObject



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

#sizeObject



19
20
21
# File 'lib/virt_disk/file_io.rb', line 19

def size
  @file.size
end