Class: PDTP::FileInfo

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

Overview

provides information about a single file on the network

Direct Known Subclasses

Client::FileInfo, Server::FileInfo

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_chunk_sizeObject

Returns the value of attribute base_chunk_size.



26
27
28
# File 'lib/pdtp/common/file_service.rb', line 26

def base_chunk_size
  @base_chunk_size
end

#file_sizeObject

Returns the value of attribute file_size.



26
27
28
# File 'lib/pdtp/common/file_service.rb', line 26

def file_size
  @file_size
end

#streamingObject

Returns the value of attribute streaming.



26
27
28
# File 'lib/pdtp/common/file_service.rb', line 26

def streaming
  @streaming
end

Instance Method Details

#chunk_data(chunkid, range = nil) ⇒ Object

returns a string containing the data for this chunk range specifies a range of bytes local to this chunk implemented in Client and Server file services



69
70
# File 'lib/pdtp/common/file_service.rb', line 69

def chunk_data(chunkid,range=nil)
end

#chunk_from_offset(offset) ⇒ Object

returns the chunkid that contains the requested byte offset



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

def chunk_from_offset(offset)
  raise "Invalid offset #{offset}" if offset < 0 or offset >= @file_size
  offset / @base_chunk_size
end

#chunk_range(chunkid) ⇒ Object

range of bytes taken up by this chunk in the entire file



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

def chunk_range(chunkid)
  start_byte = chunkid * @base_chunk_size
  end_byte = start_byte + chunk_size(chunkid) - 1
  start_byte..end_byte
end

#chunk_range_from_byte_range(byte_range, exclude_partial = true) ⇒ Object

takes a byte_range in the file and returns an equivalent chunk range if exclude_partial is true, chunks that are not completely covered by the byte range are left out



55
56
57
58
59
60
61
62
63
64
# File 'lib/pdtp/common/file_service.rb', line 55

def chunk_range_from_byte_range(byte_range,exclude_partial=true)
  min=chunk_from_offset(byte_range.first)
  min+=1 if exclude_partial and byte_range.first > min*@base_chunk_size 

  max_byte=byte_range.last
  max_byte=@file_size-1 if max_byte==-1 or max_byte>=@file_size 
  max=chunk_from_offset(max_byte)
  max-=1 if exclude_partial and max_byte<chunk_range(max).last
  min..max
end

#chunk_size(chunkid) ⇒ Object

size of the specified chunk



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

def chunk_size(chunkid) 
  raise "Invalid chunkid #{chunkid}" if chunkid<0 or chunkid>=num_chunks
  chunkid == num_chunks - 1 ? @file_size - @base_chunk_size * chunkid : @base_chunk_size
end

#num_chunksObject

number of chunks in the file



29
30
31
32
# File 'lib/pdtp/common/file_service.rb', line 29

def num_chunks
  return 0 if @file_size==0
  (@file_size - 1) / @base_chunk_size + 1  
end