def get(self):
""" ???? """
if self.readBytes < self.totalBytes:
shards = range(self.totalBytes)
os.mkdir(self.tempdir)
for i in range(0, self.totalBytes, self.readBytes):
point = shards[i: i + self.readBytes]
headers = { "Range": "bytes=%s-%s" % (point[0], point[-1]) }
filename = os.path.join(self.tempdir, str(point[-1]))
thread = self.threadPool.get()
t = thread(target=self.write_to_file, args=[filename, headers])
t.start()
while activeCount() > 1:
time.sleep(1)
results = sorted(map(int, os.listdir(self.tempdir)))
with open(self.filename, "ab") as wfd:
for result in results:
f = os.path.join(self.tempdir, str(result))
with open(f, "rb") as rfd:
content = True
while content:
content = rfd.read(1024)
wfd.write(content)
self.delete_temp_dir()
else:
self.write_to_file(filename=self.filename, useThread=False)
评论列表
文章目录