summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildstream/_cas/cascache.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 2fa143084..b875eecdd 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -272,6 +272,22 @@ class CASCache:
def objpath(self, digest):
return os.path.join(self.casdir, "objects", digest.hash[:2], digest.hash[2:])
+ # open():
+ #
+ # Open file read-only by CAS digest and return a corresponding file object.
+ #
+ # Args:
+ # digest (Digest): The digest of the object
+ # mode (str): An optional string that specifies the mode in which the file is opened.
+ #
+ def open(self, digest, mode="r"):
+ if mode not in ["r", "rb"]:
+ raise ValueError("Unsupported mode: `{}`".format(mode))
+
+ objpath = self.objpath(digest)
+
+ return open(objpath, mode=mode)
+
# add_object():
#
# Hash and write object to CAS.