Skip to content

Commit 83abc05

Browse files
committed
hashfile: add HashFile obj
1 parent bd45692 commit 83abc05

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/dvc_objects/hashfile/db.py

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from dvc_objects.errors import ObjectFormatError
1010

1111
from .hash_info import HashInfo
12+
from .obj import HashFile
1213

1314
if TYPE_CHECKING:
1415
from dvc_objects.fs.base import AnyFSPath, FileSystem
@@ -47,6 +48,13 @@ def config(self):
4748
"read_only": self.read_only,
4849
}
4950

51+
def get(self, oid: str):
52+
return HashFile(
53+
self.oid_to_path(oid),
54+
self.fs,
55+
HashInfo(self.hash_name, oid),
56+
)
57+
5058
def add(
5159
self,
5260
path: "AnyFSPath",

src/dvc_objects/hashfile/obj.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import TYPE_CHECKING
2+
3+
from dvc_objects.obj import Object
4+
5+
if TYPE_CHECKING:
6+
from .fs.base import AnyFSPath, FileSystem
7+
from .hash_info import HashInfo
8+
9+
10+
class HashFile(Object):
11+
def __init__(
12+
self, path: "AnyFSPath", fs: "FileSystem", hash_info: "HashInfo"
13+
):
14+
assert hash_info.value
15+
oid = hash_info.value
16+
super().__init__(path, fs, oid)
17+
self.hash_info = hash_info

0 commit comments

Comments
 (0)