def __init__(self, fname): self.fname = fname self.data = open(fname, 'rb').read() self.long_torrent = self._decode(self.data) self.short_torrent = copy.deepcopy(self.long_torrent) del self.short_torrent['info']['pieces'] # pieces are too long, remove them self.name = self.short_torrent['info']['name'] # name of the torrent self.length = self._get_length() # total length of files in bytes self.pretty_length = sizeof_fmt(self.length) # total length of files in pretty format
def test_sizeof_fmt(): assert number.sizeof_fmt(23) == '23.0 bytes' assert number.sizeof_fmt(1234) == '1.2 KB' assert number.sizeof_fmt(1234567) == '1.2 MB' assert number.sizeof_fmt(1234567890) == '1.1 GB' assert number.sizeof_fmt(1234567890123) == '1.1 TB' assert number.sizeof_fmt(123456789012357) == '112.3 TB'