MCPcopy Index your code
hub / github.com/pyload/pyload / extract

Method extract

module/plugins/internal/HjSplit.py:56–107  ·  view source on GitHub ↗
(self, password=None)

Source from the content-addressed store, hash-verified

54 return [self.filename[:-4]]
55
56 def extract(self, password=None):
57 file_list = []
58 size_total = 0
59 name = os.path.basename(self.filename)[:-4]
60
61 chunks = sorted(self.chunks())
62 num_chunks = len(chunks)
63
64 #: Verify HjSplit consistency
65 if len(chunks) == 1:
66 raise ArchiveError("Cannot merge just one chunk '%s'" % chunks[0])
67
68 for i in range(0, num_chunks):
69 if not exists(chunks[i]):
70 raise ArchiveError("Chunk '%s' not found" % chunks[i])
71
72 if i == 0:
73 chunk_size = os.path.getsize(chunks[i])
74
75 else:
76 if int(chunks[i][-3:]) != i + 1:
77 missing_chunk = "%s.%03d" %(os.path.splitext(chunks[i])[0], i + 1)
78 raise ArchiveError("Chunk '%s' is missing" % missing_chunk)
79
80 if i < num_chunks - 1:
81 if os.path.getsize(chunks[i]) != chunk_size:
82 raise ArchiveError("Invalid chunk size for chunk '%s'" % chunks[i])
83
84 size_total += chunk_size
85
86 else:
87 size_total += os.path.getsize(chunks[i])
88
89 #: Now do the actual merge
90 with open(fsjoin(self.dest, name), "wb") as output_file:
91 size_written = 0
92 for part_filename in chunks:
93 self.log_debug("Merging part", part_filename)
94
95 with open(part_filename, "rb") as part_file:
96 while True:
97 f_buffer = part_file.read(self.BUFFER_SIZE)
98 if f_buffer:
99 output_file.write(f_buffer)
100 size_written += len(f_buffer)
101 self.pyfile.setProgress((size_written * 100) / size_total)
102 else:
103 break
104
105 self.log_debug("Finished merging part", part_filename)
106
107 self.pyfile.setProgress(100)

Callers

nothing calls this directly

Calls 8

chunksMethod · 0.95
ArchiveErrorClass · 0.85
existsFunction · 0.85
fsjoinFunction · 0.85
log_debugMethod · 0.80
setProgressMethod · 0.80
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected