class VirtDisk::ClientHead

Attributes

end_byte_addr[R]
seek_pos[R]
size[R]
start_byte_addr[R]

Public Class Methods

new(up_stream_module) click to toggle source
# 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

Public Instance Methods

close() click to toggle source
# File lib/virt_disk/client_head.rb, line 16
def close
  @up_stream_module.close
end
mod_read(offset, len) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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