|
|
@@ -30,7 +30,7 @@ class Storage: |
|
|
|
'''A class to help read pieces of a torrent. |
|
|
|
''' |
|
|
|
|
|
|
|
def __init__(self, rootpath, files, piecelen): |
|
|
|
def __init__(self, rootpath, files, length, piecelen): |
|
|
|
''' |
|
|
|
rootpath - path to the dir of torrent files are in |
|
|
|
files - the files dictionary from the torrent info key |
|
|
@@ -45,7 +45,7 @@ class Storage: |
|
|
|
|
|
|
|
if files is None: |
|
|
|
# get length |
|
|
|
sz = self._rootpath.stat().st_size |
|
|
|
sz = length |
|
|
|
piececnt = roundup(sz, piecelen) |
|
|
|
self._pieceindex = [ [ dict(file=self._rootpath, offset=x * piecelen, size=piecelen if x < piececnt - 1 else sz - piececnt * x) ] for x in range(piececnt) ] |
|
|
|
else: |
|
|
@@ -186,7 +186,8 @@ def validate(torrent, basedir, with_file_hashes=None): |
|
|
|
torrentdir = basedir / info['name'].decode(_encoding) |
|
|
|
|
|
|
|
files = info.get('files', None) |
|
|
|
stor = Storage(torrentdir, files, info['piece length']) |
|
|
|
length = info.get('length', None) |
|
|
|
stor = Storage(torrentdir, files, length, info['piece length']) |
|
|
|
|
|
|
|
file_hashes = dict() |
|
|
|
|
|
|
@@ -382,7 +383,7 @@ class _TestCases(unittest.TestCase): |
|
|
|
self.assertEqual(hashes, { sd / 'filed.txt': bytes.fromhex('7831bd05e23877e08a97362bab2ad7bcc7d08d8f841f42e8dee545781792b987aa7637f12cec399e261f798c10d3475add0db7de2643af86a346b6b451a69ec4'), }) |
|
|
|
|
|
|
|
with open(sd / 'filed.txt', 'w') as fp: |
|
|
|
fp.write('weoifj') |
|
|
|
fp.write('w') |
|
|
|
|
|
|
|
good, bad, hashes = validate_file(tor, with_file_hashes=sha512) |
|
|
|
|
|
|
|