Class: OllamaAgent::Runtime::BlobStore
- Inherits:
-
Object
- Object
- OllamaAgent::Runtime::BlobStore
- Defined in:
- lib/ollama_agent/runtime/blob_store.rb
Overview
Content-addressed blobs under kernel_dir/blobs/aa/rest.
Instance Attribute Summary collapse
-
#blobs_root ⇒ String
readonly
Absolute path to the blobs directory (
kernel_dir/blobs).
Instance Method Summary collapse
-
#each_stored_hex ⇒ Object
Yields each lowercase 64-hex digest that exists on disk under @root.
- #exist?(sha256:) ⇒ Boolean
-
#get(sha256:) ⇒ String
Raw bytes.
-
#initialize(kernel_dir:) ⇒ BlobStore
constructor
A new instance of BlobStore.
-
#path_for_hex(sha256) ⇒ String
Absolute filesystem path for a normalized hex digest.
-
#put(content) ⇒ String
Lowercase hex SHA256.
Constructor Details
#initialize(kernel_dir:) ⇒ BlobStore
Returns a new instance of BlobStore.
15 16 17 18 |
# File 'lib/ollama_agent/runtime/blob_store.rb', line 15 def initialize(kernel_dir:) @root = File.join(File.(kernel_dir), "blobs") @blobs_root = @root end |
Instance Attribute Details
#blobs_root ⇒ String (readonly)
Returns absolute path to the blobs directory (kernel_dir/blobs).
13 14 15 |
# File 'lib/ollama_agent/runtime/blob_store.rb', line 13 def blobs_root @blobs_root end |
Instance Method Details
#each_stored_hex ⇒ Object
Yields each lowercase 64-hex digest that exists on disk under @root.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ollama_agent/runtime/blob_store.rb', line 55 def each_stored_hex return enum_for(:each_stored_hex) unless block_given? return unless File.directory?(@root) Dir.each_child(@root) do |dir2| sub = File.join(@root, dir2) next unless dir2.length == 2 && File.directory?(sub) Dir.each_child(sub) do |tail| hex = "#{dir2}#{tail}" yield hex if hex.match?(/\A[0-9a-f]{64}\z/) end end end |
#exist?(sha256:) ⇒ Boolean
45 46 47 |
# File 'lib/ollama_agent/runtime/blob_store.rb', line 45 def exist?(sha256:) File.exist?(blob_path(normalize_sha(sha256))) end |
#get(sha256:) ⇒ String
Returns raw bytes.
35 36 37 38 39 40 41 42 |
# File 'lib/ollama_agent/runtime/blob_store.rb', line 35 def get(sha256:) path = blob_path(normalize_sha(sha256)) raise BlobNotFound, path unless File.exist?(path) bytes = File.binread(path) verify_bytes!(bytes, normalize_sha(sha256)) bytes end |
#path_for_hex(sha256) ⇒ String
Returns absolute filesystem path for a normalized hex digest.
50 51 52 |
# File 'lib/ollama_agent/runtime/blob_store.rb', line 50 def path_for_hex(sha256) blob_path(normalize_sha(sha256)) end |
#put(content) ⇒ String
Returns lowercase hex SHA256.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ollama_agent/runtime/blob_store.rb', line 22 def put(content) bytes = content.b hex = Digest::SHA256.hexdigest(bytes) path = blob_path(hex) FileUtils.mkdir_p(File.dirname(path)) return verify_existing!(path, bytes, hex) if File.exist?(path) FileAtomicSwap.write_bytes!(path, bytes) hex end |