MCPcopy
hub / github.com/borgbackup/borg / compress_entry

Method compress_entry

src/borg/cache.py:418–439  ·  view source on GitHub ↗

compress a files cache entry: - use the ChunkIndex to "compress" the entry's chunks list (256bit key + 32bit size -> 32bit index). - use msgpack to pack the entry (reduce memory usage by packing and having less python objects). Note: the result is only valid while

(self, entry)

Source from the content-addressed store, hash-verified

416 self.start_backup = start_backup
417
418 def compress_entry(self, entry):
419 """
420 compress a files cache entry:
421
422 - use the ChunkIndex to "compress" the entry's chunks list (256bit key + 32bit size -> 32bit index).
423 - use msgpack to pack the entry (reduce memory usage by packing and having less python objects).
424
425 Note: the result is only valid while the ChunkIndex is in memory!
426 """
427 assert isinstance(self.chunks, ChunkIndex), f"{self.chunks} is not a ChunkIndex"
428 assert isinstance(entry, FileCacheEntry)
429 compressed_chunks = []
430 for id, size in entry.chunks:
431 cie = self.chunks[id] # may raise KeyError if chunk id is not in repo
432 if cie.size == 0: # size is not known in the chunks index yet
433 self.chunks[id] = cie._replace(size=size)
434 else:
435 assert size == cie.size, f"{size} != {cie.size}"
436 idx = self.chunks.k_to_idx(id)
437 compressed_chunks.append(idx)
438 entry = entry._replace(chunks=compressed_chunks)
439 return msgpack.packb(entry)
440
441 def decompress_entry(self, entry_packed):
442 """reverse operation of compress_entry"""

Callers 4

_build_files_cacheMethod · 0.95
_read_files_cacheMethod · 0.95
memorize_fileMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected