| 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) |