Skip to content

Commit 1a5509a

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

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
@@ -598,14 +598,20 @@ def fetch(self, key, _stacklevel=0):
598598

599599
@staticmethod
600600
def _read(path):
601+
import lzma
601602
from pickle import load
602-
with open(path, "rb") as inf:
603-
return load(inf)
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):
612+
import lzma
607613
from pickle import HIGHEST_PROTOCOL, dump
608-
with open(path, "wb") as outf:
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)