Class: AtlasRb::Blob
Overview
The binary content backing a FileSet (or attached directly to a Work).
Blobs are the bytes-on-disk layer of the hierarchy. Operations on this class deal with raw octet streams: uploading new content, replacing content on an existing Blob, and streaming downloads via a chunk handler so very large files don't have to be buffered in memory.
Constant Summary collapse
- ROUTE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Atlas REST endpoint prefix for this resource.
"/files/"
Constants included from FaradayHelper
FaradayHelper::ASSERTION_AUDIENCE, FaradayHelper::ASSERTION_ISSUER, FaradayHelper::ASSERTION_TTL
Class Method Summary collapse
-
.content(id, nuid: nil, on_behalf_of: nil) {|chunk| ... } ⇒ Hash
Stream the Blob's binary content through a caller-supplied block.
-
.create(id, blob_path, original_filename, expected_digest: nil, idempotency_key: nil, nuid: nil, on_behalf_of: nil) ⇒ Hash
Upload a new Blob attached to a Work.
-
.destroy(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Delete a Blob (the bytes and the metadata record).
-
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Fetch a single Blob's metadata record (not its bytes — see Blob.content).
-
.update(id, blob_path, expected_digest: nil, nuid: nil, on_behalf_of: nil) ⇒ Hash
Replace the bytes of an existing Blob in-place.
Methods inherited from Resource
find_many, history, mods_version, mods_versions, permissions, preview
Methods included from FaradayHelper
#connection, #multipart, #system_connection, #with_file_part
Class Method Details
.content(id, nuid: nil, on_behalf_of: nil) {|chunk| ... } ⇒ Hash
Stream the Blob's binary content through a caller-supplied block.
The body is not buffered — each chunk Faraday receives is yielded
to chunk_handler immediately, making this safe for files larger than
available memory. The first chunk's response headers are captured and
returned so callers can inspect Content-Type, Content-Length, etc.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/atlas_rb/blob.rb', line 64 def self.content(id, nuid: nil, on_behalf_of: nil, &chunk_handler) headers = {} connection({}, nuid, on_behalf_of: on_behalf_of).get("#{ROUTE}#{id}/content") do |req| req..on_data = proc do |chunk, _bytes_received, env| headers = env.response_headers if headers.empty? && env chunk_handler.call(chunk) end end headers end |
.create(id, blob_path, original_filename, expected_digest: nil, idempotency_key: nil, nuid: nil, on_behalf_of: nil) ⇒ Hash
Streams the file (FD closed deterministically); a multi-GB upload is not buffered in memory. See FaradayHelper#with_file_part.
Upload a new Blob attached to a Work.
original_filename is preserved separately from the upload's
File.basename(blob_path) because the on-disk path is often a temp
file name (RackMultipart...tmp) — Atlas needs the user-facing name
for download UX.
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/atlas_rb/blob.rb', line 116 def self.create(id, blob_path, original_filename, expected_digest: nil, idempotency_key: nil, nuid: nil, on_behalf_of: nil) with_file_part(blob_path) do |part| payload = { work_id: id, original_filename: original_filename, binary: part } payload[:expected_digest] = expected_digest if expected_digest AtlasRb::Mash.new(JSON.parse( multipart(nuid, on_behalf_of: on_behalf_of, idempotency_key: idempotency_key) .post(ROUTE, payload)&.body ))['blob'] end end |
.destroy(id, nuid: nil, on_behalf_of: nil) ⇒ Faraday::Response
Delete a Blob (the bytes and the metadata record).
142 143 144 |
# File 'lib/atlas_rb/blob.rb', line 142 def self.destroy(id, nuid: nil, on_behalf_of: nil) connection({}, nuid, on_behalf_of: on_behalf_of).delete(ROUTE + id) end |
.find(id, nuid: nil, on_behalf_of: nil) ⇒ Hash
Fetch a single Blob's metadata record (not its bytes — see content).
36 37 38 39 40 |
# File 'lib/atlas_rb/blob.rb', line 36 def self.find(id, nuid: nil, on_behalf_of: nil) AtlasRb::Mash.new(JSON.parse( connection({}, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id)&.body ))['blob'] end |
.update(id, blob_path, expected_digest: nil, nuid: nil, on_behalf_of: nil) ⇒ Hash
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/atlas_rb/blob.rb', line 171 def self.update(id, blob_path, expected_digest: nil, nuid: nil, on_behalf_of: nil) with_file_part(blob_path) do |part| payload = { binary: part } payload[:expected_digest] = expected_digest if expected_digest AtlasRb::Mash.new(JSON.parse( multipart(nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id, payload)&.body )) end end |