Blob is no more. Notes now always have content.

This commit is contained in:
Andrew Mulbrook 2026-03-26 00:36:01 -05:00
parent 5df3c81417
commit ffefe4dd21
4 changed files with 28 additions and 48 deletions

View file

@ -13,7 +13,7 @@ from .db import Sqlite3Trove, NOTE_ROOT_ID
from . import trove as tr
from .trove import Note, Trove, TreeNote, BlobNote, TreeEntry, NoteNotFound, ObjectId
from .trove import Note, Trove, TreeNote, TreeEntry, NoteNotFound, ObjectId
class NoteImpl(Note):
@ -50,16 +50,11 @@ class NoteImpl(Note):
def set_raw_metadata(self, key: str, value: bytes) -> None:
self._db.write_metadata(self._object_id, key, value)
class BlobNoteImpl(NoteImpl, BlobNote):
"""Concrete BlobNote: a blob object in the store with metadata access."""
# Blob protocol
def read(self) -> bytes:
def read_content(self) -> bytes:
data = self._db.read_object(self._object_id)
return data if data is not None else b""
def write(self, data: bytes) -> None:
def write_content(self, data: bytes) -> None:
self._db.write_content(self._object_id, data)
@ -147,13 +142,13 @@ class TroveImpl:
raise NoteNotFound(note_id)
if self._db.is_tree(note_id) or info.type == "inode/directory":
return TreeNoteImpl(self, note_id)
return BlobNoteImpl(self, note_id)
return NoteImpl(self, note_id)
def create_blob(self, data: bytes | None = None,
dtype: str = "application/octet-stream") -> BlobNote:
dtype: str = "application/octet-stream") -> Note:
"""Create a new blob object and return a BlobNote for it."""
obj_id = self._db.write_blob(data or b"", dtype=dtype)
return BlobNoteImpl(self, obj_id)
return NoteImpl(self, obj_id)
def get_root(self) -> TreeNote:
"""Return the root TreeNote (always id=NOTE_ROOT_ID)."""