Class: PDTP::Server::FileService
- Inherits:
-
FileService
- Object
- FileService
- PDTP::Server::FileService
- Defined in:
- lib/pdtp/server/file_service.rb,
lib/pdtp/server/file_service_protocol.rb
Overview
The file service provides utilities for determining various information about files.
Defined Under Namespace
Classes: Protocol
Instance Attribute Summary collapse
-
#default_chunk_size ⇒ Object
Returns the value of attribute default_chunk_size.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#get_chunk_hash(url, chunk_id) ⇒ Object
returns the SHA256 hash of the specified chunk.
-
#get_info(url) ⇒ Object
Retrieve information about a file.
-
#get_local_path(url) ⇒ Object
returns the path of this file on the local filesystem.
-
#initialize ⇒ FileService
constructor
A new instance of FileService.
Constructor Details
#initialize ⇒ FileService
Returns a new instance of FileService.
65 66 67 68 |
# File 'lib/pdtp/server/file_service.rb', line 65 def initialize @root = '' @default_chunk_size = 512 end |
Instance Attribute Details
#default_chunk_size ⇒ Object
Returns the value of attribute default_chunk_size.
63 64 65 |
# File 'lib/pdtp/server/file_service.rb', line 63 def default_chunk_size @default_chunk_size end |
#root ⇒ Object
Returns the value of attribute root.
63 64 65 |
# File 'lib/pdtp/server/file_service.rb', line 63 def root @root end |
Instance Method Details
#get_chunk_hash(url, chunk_id) ⇒ Object
returns the SHA256 hash of the specified chunk
99 100 101 |
# File 'lib/pdtp/server/file_service.rb', line 99 def get_chunk_hash(url,chunk_id) Digest::SHA256.hexdigest(get_info(url).chunk_data(chunk_id)) rescue nil end |
#get_info(url) ⇒ Object
Retrieve information about a file. This should really be persistent FIXME the only authentication regarding registered files is performed by checking whether the registered file exists
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pdtp/server/file_service.rb', line 73 def get_info(url) begin host = URI.split(url)[2] #FIXME we should check host against a list of known hosts here info = FileInfo.new info.streaming = false info.base_chunk_size = @default_chunk_size info.path = get_local_path(url) raise if File.directory?(info.path) info.file_size = File.size?(info.path) return nil if info.file_size == 0 or info.file_size.nil? rescue return nil end info end |
#get_local_path(url) ⇒ Object
returns the path of this file on the local filesystem
92 93 94 95 96 |
# File 'lib/pdtp/server/file_service.rb', line 92 def get_local_path(url) path = URI.split(url)[5] path = path[1..path.size-1] #remove leading / (Pathname.new(@root) + path).to_s end |