Class: QuartzTorrent::Metainfo::FileInfo
- Inherits:
-
Object
- Object
- QuartzTorrent::Metainfo::FileInfo
- Defined in:
- lib/quartz_torrent/metainfo.rb
Overview
Information about a file contained in the torrent.
Instance Attribute Summary collapse
-
#length ⇒ Object
Length of the file.
-
#path ⇒ Object
Relative path to the file.
Class Method Summary collapse
-
.createFromBdecode(bdecode) ⇒ Object
Create a FileInfo object from a bdecoded structure.
Instance Method Summary collapse
-
#initialize(length = nil, path = nil) ⇒ FileInfo
constructor
A new instance of FileInfo.
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
#length ⇒ Object
Length of the file.
31 32 33 |
# File 'lib/quartz_torrent/metainfo.rb', line 31 def length @length end |
#path ⇒ Object
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 |