Add chunk store and chunk list helper

This commit is contained in:
liyaxing
2023-09-08 15:52:05 +08:00
parent 1e5b9afd0f
commit e8e3812d28
6 changed files with 164 additions and 28 deletions
+26
View File
@@ -0,0 +1,26 @@
import os
import logging
from ..object import FileBlobStorage
from .chunk import ChunkID
class ChunkStore:
def __init__(self, root_dir: str):
logging.info(f"will init chunk store, root_dir={root_dir}")
if not os.path.exists(root_dir):
os.makedirs(root_dir)
self.root = root_dir
self.blob = FileBlobStorage(root_dir)
def put_chunk(self, chunk_id: ChunkID, contents: bytes):
self.blob.put(chunk_id, contents)
def get_chunk(self, chunk_id: ChunkID) -> bytes:
return self.blob.get(chunk_id)
def delete_chunk(self, chunk_id: ChunkID):
self.blob.delete(chunk_id)