11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4- using System . Linq ;
54using System . Security . Cryptography ;
65
76namespace BencodeNET . Objects
87{
9- public class TorrentFile
8+ public class TorrentFile : BObject < BDictionary >
109 {
1110 private readonly DateTime _epoch = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
1211
13- private readonly BDictionary _data = new BDictionary ( ) ;
14-
1512 public BDictionary Info
1613 {
17- get { return ( BDictionary ) _data [ Fields . Info ] ; }
18- set { _data [ Fields . Info ] = value ; }
14+ get { return ( BDictionary ) Value [ Fields . Info ] ; }
15+ set { Value [ Fields . Info ] = value ; }
1916 }
2017
2118 public string Announce
2219 {
2320 get
2421 {
25- if ( ! _data . ContainsKey ( Fields . Announce ) )
22+ if ( ! Value . ContainsKey ( Fields . Announce ) )
2623 return null ;
27- return _data [ Fields . Announce ] . ToString ( ) ;
24+ return Value [ Fields . Announce ] . ToString ( ) ;
2825 }
29- set { _data [ Fields . Announce ] = new BString ( value ) ; }
26+ set { Value [ Fields . Announce ] = new BString ( value ) ; }
3027 }
3128
3229 public BList AnnounceList
3330 {
34- get { return ( BList ) _data [ Fields . AnnounceList ] ?? new BList ( ) ; }
35- set { _data [ Fields . AnnounceList ] = value ; }
31+ get { return ( BList ) Value [ Fields . AnnounceList ] ?? new BList ( ) ; }
32+ set { Value [ Fields . AnnounceList ] = value ; }
3633 }
3734
3835 public DateTime CreationDate
3936 {
4037 get
4138 {
42- var unixTime = ( BNumber ) _data [ Fields . CreationDate ] ;
39+ var unixTime = ( BNumber ) Value [ Fields . CreationDate ] ;
4340 return _epoch . AddSeconds ( unixTime ) ;
4441 }
4542 set
4643 {
4744 var unixTime = value . Subtract ( _epoch ) . TotalSeconds . ToString ( ) ;
48- _data [ Fields . CreationDate ] = new BString ( unixTime ) ;
45+ Value [ Fields . CreationDate ] = new BString ( unixTime ) ;
4946 }
5047 }
5148
5249 public string Comment
5350 {
5451 get
5552 {
56- if ( ! _data . ContainsKey ( Fields . Comment ) )
53+ if ( ! Value . ContainsKey ( Fields . Comment ) )
5754 return null ;
58- return _data [ Fields . Comment ] . ToString ( ) ;
55+ return Value [ Fields . Comment ] . ToString ( ) ;
5956 }
60- set { _data [ Fields . Comment ] = new BString ( value ) ; }
57+ set { Value [ Fields . Comment ] = new BString ( value ) ; }
6158 }
6259
6360 public string CreatedBy
6461 {
6562 get
6663 {
67- if ( ! _data . ContainsKey ( Fields . CreatedBy ) )
64+ if ( ! Value . ContainsKey ( Fields . CreatedBy ) )
6865 return null ;
69- return _data [ Fields . CreatedBy ] . ToString ( ) ;
66+ return Value [ Fields . CreatedBy ] . ToString ( ) ;
7067 }
71- set { _data [ Fields . CreatedBy ] = new BString ( value ) ; }
68+ set { Value [ Fields . CreatedBy ] = new BString ( value ) ; }
7269 }
7370
7471 public string Encoding
7572 {
7673 get
7774 {
78- if ( ! _data . ContainsKey ( Fields . Encoding ) )
75+ if ( ! Value . ContainsKey ( Fields . Encoding ) )
7976 return null ;
80- return _data [ Fields . Encoding ] . ToString ( ) ;
77+ return Value [ Fields . Encoding ] . ToString ( ) ;
8178 }
82- set { _data [ Fields . Encoding ] = new BString ( value ) ; }
79+ set { Value [ Fields . Encoding ] = new BString ( value ) ; }
8380 }
8481
8582 public string CalculateInfoHash ( )
@@ -113,8 +110,8 @@ public static byte[] CalculateInfoHashBytes(BDictionary info)
113110
114111 public IBObject this [ BString key ]
115112 {
116- get { return _data [ key ] ; }
117- set { _data [ key ] = value ; }
113+ get { return Value [ key ] ; }
114+ set { Value [ key ] = value ; }
118115 }
119116
120117 public static bool operator == ( TorrentFile first , TorrentFile second )
@@ -130,6 +127,11 @@ public IBObject this[BString key]
130127 return ! ( first == second ) ;
131128 }
132129
130+ public override TStream EncodeToStream < TStream > ( TStream stream )
131+ {
132+ return Value . EncodeToStream ( stream ) ;
133+ }
134+
133135 public override bool Equals ( object other )
134136 {
135137 var torrent = other as TorrentFile ;
@@ -156,12 +158,12 @@ public override int GetHashCode()
156158 throw new NotImplementedException ( ) ;
157159 }
158160
159- public TorrentFile ( )
161+ public TorrentFile ( ) : this ( new BDictionary ( ) )
160162 { }
161163
162164 public TorrentFile ( BDictionary torrent )
163165 {
164- _data = torrent ;
166+ Value = torrent ;
165167 }
166168
167169 private static class Fields
0 commit comments