MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / write

Method write

plugins/Bigfile/BigfilePlugin.py:425–451  ·  view source on GitHub ↗
(self, inner_path, content)

Source from the content-addressed store, hash-verified

423 del self.piecefields[sha512]
424
425 def write(self, inner_path, content):
426 if "|" not in inner_path:
427 return super(SiteStoragePlugin, self).write(inner_path, content)
428
429 # Write to specific position by passing |{pos} after the filename
430 inner_path, file_range = inner_path.split("|")
431 pos_from, pos_to = map(int, file_range.split("-"))
432 file_path = self.getPath(inner_path)
433
434 # Create dir if not exist
435 file_dir = os.path.dirname(file_path)
436 if not os.path.isdir(file_dir):
437 os.makedirs(file_dir)
438
439 if not os.path.isfile(file_path):
440 file_info = self.site.content_manager.getFileInfo(inner_path)
441 self.createSparseFile(inner_path, file_info["size"])
442
443 # Write file
444 with open(file_path, "rb+") as file:
445 file.seek(pos_from)
446 if hasattr(content, 'read'): # File-like object
447 shutil.copyfileobj(content, file) # Write buff to disk
448 else: # Simple string
449 file.write(content)
450 del content
451 self.onUpdated(inner_path)
452
453 def checkBigfile(self, inner_path):
454 file_info = self.site.content_manager.getFileInfo(inner_path)

Callers 6

actionBigfileUploadMethod · 0.45
hashBigfileMethod · 0.45
hashFileMethod · 0.45
createBigfileMethod · 0.45
testSparseFileMethod · 0.45
testNullFileReadMethod · 0.45

Calls 5

createSparseFileMethod · 0.95
onUpdatedMethod · 0.95
getPathMethod · 0.80
getFileInfoMethod · 0.45
seekMethod · 0.45

Tested by 3

createBigfileMethod · 0.36
testSparseFileMethod · 0.36
testNullFileReadMethod · 0.36