Skip to content

Commit eabed97

Browse files
PersistentDict: compress pickled data
1 parent 78bba69 commit eabed97

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pytools/persistent_dict.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,19 @@ def fetch(self, key, _stacklevel=0):
599599
@staticmethod
600600
def _read(path):
601601
from pickle import load
602-
with open(path, "rb") as inf:
603-
return load(inf)
602+
import lzma
603+
try:
604+
with lzma.open(path, "rb") as inf:
605+
return load(inf)
606+
except lzma.LZMAError:
607+
with open(path, "rb") as inf:
608+
return load(inf)
604609

605610
@staticmethod
606611
def _write(path, value):
607612
from pickle import HIGHEST_PROTOCOL, dump
608-
with open(path, "wb") as outf:
613+
import lzma
614+
with lzma.open(path, "wb") as outf:
609615
dump(value, outf, protocol=HIGHEST_PROTOCOL)
610616

611617
def _item_dir(self, hexdigest_key):

0 commit comments

Comments
 (0)