Class: QuartzTorrent::Metainfo::FileInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/quartz_torrent/metainfo.rb

Overview

Information about a file contained in the torrent.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length = nil, path = nil) ⇒ FileInfo

Returns a new instance of FileInfo.



22
23
24
25
# File 'lib/quartz_torrent/metainfo.rb', line 22

def initialize(length = nil, path = nil)
  @length = length
  @path = path
end

Instance Attribute Details

#lengthObject

Length of the file.



31
32
33
# File 'lib/quartz_torrent/metainfo.rb', line 31

def length
  @length
end

#pathObject

Relative path to the file. For a single-file torrent this is simply the name of the file. For a multi-file torrent, this is the directory names from the torrent and the filename separated by the file separator.



29
30
31
# File 'lib/quartz_torrent/metainfo.rb', line 29

def path
  @path
end

Class Method Details

.createFromBdecode(bdecode) ⇒ Object

Create a FileInfo object from a bdecoded structure.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/quartz_torrent/metainfo.rb', line 34

def self.createFromBdecode(bdecode)
  result = FileInfo.new
  result.length = Metainfo.valueOrException(bdecode['length'], "Torrent metainfo listed multiple files, and one is missing the length property.")
  path = Metainfo.valueOrException(bdecode['path'], "Torrent metainfo listed multiple files, and one is missing the path property.")

  result.path = ""
  path.each do |part|
    result.path << File::SEPARATOR if result.path.length > 0
    result.path << part
  end
  
  result
end