ITADN

add example for calculate_piece_size

#58Closedmilahu 创建于 2025-03-12
M
milahucommented
or add a convenience function `get_content_size` `size` is the actual size, not the apparent size https://stackoverflow.com/a/1392549/29400002 ```py import os def get_size(start_path = '.'): total_size = 0 for dirpath, dirnames, filenames in os.walk(start_path): for f in filenames: fp = os.path.join(dirpath, f) # skip if it is symbolic link if not os.path.islink(fp): total_size += os.path.getsize(fp) return total_size # print(get_size(), 'bytes') import torf content_path = "Some.Content" content_size = get_size(content_path) piece_size = torf.Torrent.calculate_piece_size(content_size) ```
关闭于 2025-03-13 4 条评论