MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / checkBigfile

Method checkBigfile

plugins/Bigfile/BigfilePlugin.py:453–475  ·  view source on GitHub ↗
(self, inner_path)

Source from the content-addressed store, hash-verified

451 self.onUpdated(inner_path)
452
453 def checkBigfile(self, inner_path):
454 file_info = self.site.content_manager.getFileInfo(inner_path)
455 if not file_info or (file_info and "piecemap" not in file_info): # It's not a big file
456 return False
457
458 self.site.settings["has_bigfile"] = True
459 file_path = self.getPath(inner_path)
460 sha512 = file_info["sha512"]
461 piece_num = int(math.ceil(float(file_info["size"]) / file_info["piece_size"]))
462 if os.path.isfile(file_path):
463 if sha512 not in self.piecefields:
464 if open(file_path, "rb").read(128) == b"\0" * 128:
465 piece_data = b"\x00"
466 else:
467 piece_data = b"\x01"
468 self.log.debug("%s: File exists, but not in piecefield. Filling piecefiled with %s * %s." % (inner_path, piece_num, piece_data))
469 self.piecefields[sha512].frombytes(piece_data * piece_num)
470 else:
471 self.log.debug("Creating bigfile: %s" % inner_path)
472 self.createSparseFile(inner_path, file_info["size"], sha512)
473 self.piecefields[sha512].frombytes(b"\x00" * piece_num)
474 self.log.debug("Created bigfile: %s" % inner_path)
475 return True
476
477 def openBigfile(self, inner_path, prebuffer=0):
478 if not self.checkBigfile(inner_path):

Callers 2

openBigfileMethod · 0.95
optionalDownloadedMethod · 0.80

Calls 5

createSparseFileMethod · 0.95
getPathMethod · 0.80
getFileInfoMethod · 0.45
readMethod · 0.45
frombytesMethod · 0.45

Tested by

no test coverage detected