gzip compress link metadata for a slight reduction in disk space

This commit is contained in:
Danny McClanahan 2023-09-03 19:15:37 -04:00
parent 7591507dfe
commit 5a42ae469c
No known key found for this signature in database
GPG Key ID: CE8D0DA71DEFC1DF
1 changed files with 3 additions and 2 deletions

View File

@ -5,6 +5,7 @@
# mypy: strict-optional=False
import email.errors
import gzip
import json
import mimetypes
import os
@ -437,7 +438,7 @@ class RequirementPreparer:
try:
cached_path = self._metadata_cache.cache_path(req.link)
os.makedirs(str(cached_path.parent), exist_ok=True)
with cached_path.open("rb") as f:
with gzip.open(cached_path, mode="rt", encoding="utf-8") as f:
logger.debug(
"found cached metadata for link %s at %s", req.link, f.name
)
@ -466,7 +467,7 @@ class RequirementPreparer:
try:
cached_path = self._metadata_cache.cache_path(req.link)
os.makedirs(str(cached_path.parent), exist_ok=True)
with cached_path.open("w") as f:
with gzip.open(cached_path, mode="wt", encoding="utf-8") as f:
cacheable_dist = CacheableDist.from_dist(req.link, metadata_dist)
args = cacheable_dist.to_json()
logger.debug("caching metadata for link %s at %s", req.link, f.name)