Class: PDTP::Server::FileInfo

Inherits:
FileInfo
  • Object
show all
Defined in:
lib/pdtp/server/file_info.rb

Overview

The server specific file utilities

Instance Attribute Summary collapse

Attributes inherited from FileInfo

#base_chunk_size, #file_size, #streaming

Instance Method Summary collapse

Methods inherited from FileInfo

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

Instance Attribute Details

#pathObject

Returns the value of attribute path.



29
30
31
# File 'lib/pdtp/server/file_info.rb', line 29

def path
  @path
end

Instance Method Details

#chunk_data(chunkid, range = nil) ⇒ Object

Return a raw string of chunk data. The range parameter is local to this chunk and zero based



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pdtp/server/file_info.rb', line 33

def chunk_data(chunkid, range = nil)
  begin
    range = 0..chunk_size(chunkid) - 1 if range.nil? # full range of chunk if range isnt specified
    raise if range.first < 0 or range.last >= chunk_size(chunkid)
    start = range.first + chunkid * @base_chunk_size 
    size = range.last - range.first + 1 
    file = open @path
    file.pos = start
    file.read size
  rescue nil
  end
end

#read(range) ⇒ Object

reads the specified byte range from the file and returns it as a string



47
48
49
50
51
52
53
54
55
# File 'lib/pdtp/server/file_info.rb', line 47

def read(range)
  #puts "READING: range=#{range}"
  begin
    file = open @path
    file.pos = range.first
    file.read range.last - range.first + 1
  rescue nil
  end
end