Class: PDTP::Client::FileInfo

Inherits:
FileInfo
  • Object
show all
Defined in:
lib/pdtp/client/file_service.rb

Overview

The client specific file utilities. Most importantly, handling the data buffer.

Instance Attribute Summary

Attributes inherited from FileInfo

#base_chunk_size, #file_size, #streaming

Instance Method Summary collapse

Methods inherited from FileInfo

#chunk_data, #chunk_from_offset, #chunk_range, #chunk_range_from_byte_range, #chunk_size, #num_chunks

Constructor Details

#initialize(filename, io = nil) ⇒ FileInfo

Returns a new instance of FileInfo.



31
32
33
# File 'lib/pdtp/client/file_service.rb', line 31

def initialize(filename, io = nil)
  @buffer = FileBuffer.new io || open(filename, 'w')
end

Instance Method Details

#bytes_downloadedObject

Return the number of bytes currently stored



49
50
51
# File 'lib/pdtp/client/file_service.rb', line 49

def bytes_downloaded
  @buffer.bytes_stored
end

#read(range) ⇒ Object

Read a range of data out of buffer. Takes a ruby Range object



41
42
43
44
45
46
# File 'lib/pdtp/client/file_service.rb', line 41

def read(range)
  begin
    @buffer.read range
  rescue nil
  end
end

#write(start_pos, data) ⇒ Object

Write data into buffer starting at start_pos



36
37
38
# File 'lib/pdtp/client/file_service.rb', line 36

def write(start_pos,data)
  @buffer.write start_pos, data
end