Skip to content

Commit d05c9ab

Browse files
PersistentDict: compress pickled data
1 parent da5d9e6 commit d05c9ab

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

pytools/persistent_dict.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,20 @@ def fetch(self, key, _stacklevel=0):
582582

583583
@staticmethod
584584
def _read(path):
585+
import lzma
585586
from pickle import load
586-
with open(path, "rb") as inf:
587-
return load(inf)
587+
try:
588+
with lzma.open(path, "rb") as inf:
589+
return load(inf)
590+
except lzma.LZMAError:
591+
with open(path, "rb") as inf:
592+
return load(inf)
588593

589594
@staticmethod
590595
def _write(path, value):
596+
import lzma
591597
from pickle import HIGHEST_PROTOCOL, dump
592-
with open(path, "wb") as outf:
598+
with lzma.open(path, "wb") as outf:
593599
dump(value, outf, protocol=HIGHEST_PROTOCOL)
594600

595601
def _item_dir(self, hexdigest_key):

0 commit comments

Comments
 (0)