Class: VirtDisk::BlockFile

Inherits:
Object
  • Object
show all
Defined in:
lib/virt_disk/block_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ BlockFile

Returns a new instance of BlockFile.



5
6
7
8
# File 'lib/virt_disk/block_file.rb', line 5

def initialize(path)
  @path = path
  @file = defined?(VirtFS) ? VirtFS::VFile.open(path) : File.open(path)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/virt_disk/block_file.rb', line 3

def path
  @path
end

Instance Method Details

#block_sizeObject



10
11
12
# File 'lib/virt_disk/block_file.rb', line 10

def block_size
  1
end

#closeObject



18
19
20
# File 'lib/virt_disk/block_file.rb', line 18

def close
  @file.close
end

#raw_read(start, len) ⇒ Object



22
23
24
25
# File 'lib/virt_disk/block_file.rb', line 22

def raw_read(start, len)
  @file.seek start
  @file.read len
end

#raw_write(buf, start, len) ⇒ Object



27
28
29
30
# File 'lib/virt_disk/block_file.rb', line 27

def raw_write(buf, start, len)
  @file.seek start
  @file.write buf, len
end

#sizeObject



14
15
16
# File 'lib/virt_disk/block_file.rb', line 14

def size
  @file.size
end