|
| 1 | +##============================================================================== |
| 2 | +## Blob + Blobentry CRUD interface |
| 3 | +##============================================================================== |
| 4 | + |
| 5 | +""" |
| 6 | +Convenience wrapper to load a Blob for a given variable and Blobentry label. |
| 7 | +
|
| 8 | +$(METHODLIST) |
| 9 | +""" |
| 10 | +function loadBlob_Variable end |
| 11 | + |
| 12 | +""" |
| 13 | +Convenience wrapper to save a Blob to a Blobstore and a Blobentry to a variable. |
| 14 | +$(METHODLIST) |
| 15 | +""" |
| 16 | +function saveBlob_Variable! end |
| 17 | + |
| 18 | +""" |
| 19 | +Convenience wrapper to delete a Blob form a Blobstore and its Blobentry from a variable. |
| 20 | +$(METHODLIST) |
| 21 | +""" |
| 22 | +function deleteBlob_Variable! end |
| 23 | + |
| 24 | +""" |
| 25 | +Convenience wrapper to load a Blob for a given graph and Blobentry label. |
| 26 | +
|
| 27 | +$(METHODLIST) |
| 28 | +""" |
| 29 | +function loadBlob_Graph end |
| 30 | + |
| 31 | +""" |
| 32 | +Convenience wrapper to save a Blob to a Blobstore and a Blobentry to a graph. |
| 33 | +
|
| 34 | +$(METHODLIST) |
| 35 | +""" |
| 36 | +function saveBlob_Graph! end |
| 37 | + |
| 38 | +""" |
| 39 | +Convenience wrapper to delete a Blob from a Blobstore and its Blobentry from a graph. |
| 40 | +
|
| 41 | +$(METHODLIST) |
| 42 | +""" |
| 43 | +function deleteBlob_Graph! end |
| 44 | + |
| 45 | +""" |
| 46 | +Convenience wrapper to load a Blob for a given agent and Blobentry label. |
| 47 | +
|
| 48 | +$(METHODLIST) |
| 49 | +""" |
| 50 | +function loadBlob_Agent end |
| 51 | + |
| 52 | +""" |
| 53 | +Convenience wrapper to save a Blob to a Blobstore and a Blobentry to an agent. |
| 54 | +
|
| 55 | +$(METHODLIST) |
| 56 | +""" |
| 57 | +function saveBlob_Agent! end |
| 58 | + |
| 59 | +""" |
| 60 | +Convenience wrapper to delete a Blob from a Blobstore and its Blobentry from an agent. |
| 61 | +
|
| 62 | +$(METHODLIST) |
| 63 | +""" |
| 64 | +function deleteBlob_Agent! end |
| 65 | + |
| 66 | +function loadBlob_Variable( |
| 67 | + dfg::AbstractDFG, |
| 68 | + variable_label::Symbol, |
| 69 | + entry_label::Symbol; |
| 70 | + # hashfunction = sha256, |
| 71 | + # checkhash::Bool = true, |
| 72 | +) |
| 73 | + entry = getBlobentry(dfg, variable_label, entry_label) |
| 74 | + blob = getBlob(dfg, entry) |
| 75 | + # checkhash && assertHash(de, db; hashfunction) |
| 76 | + return entry, blob |
| 77 | +end |
| 78 | + |
| 79 | +function saveBlob_Variable!( |
| 80 | + dfg::AbstractDFG, |
| 81 | + variable_label::Symbol, |
| 82 | + blob::Vector{UInt8}, |
| 83 | + entry::Blobentry, |
| 84 | +) |
| 85 | + addBlobentry!(dfg, variable_label, entry) |
| 86 | + addBlob!(dfg, entry, blob) |
| 87 | + return entry |
| 88 | +end |
| 89 | + |
| 90 | +function saveBlob_Variable!( |
| 91 | + dfg::AbstractDFG, |
| 92 | + variable_label::Symbol, |
| 93 | + blob::Vector{UInt8}, |
| 94 | + entry_label::Symbol, |
| 95 | + blobstore::Symbol = :default; |
| 96 | + blobentry_kwargs..., |
| 97 | +) |
| 98 | + entry = Blobentry(entry_label, blobstore; blobentry_kwargs...) |
| 99 | + return saveBlob_Variable!(dfg, variable_label, blob, entry) |
| 100 | +end |
| 101 | + |
| 102 | +function deleteBlob_Variable!(dfg::AbstractDFG, variable_label::Symbol, entry_label::Symbol) |
| 103 | + entry = getBlobentry(dfg, variable_label, entry_label) |
| 104 | + deleteBlobentry!(dfg, variable_label, entry_label) |
| 105 | + deleteBlob!(dfg, entry) |
| 106 | + return 2 |
| 107 | +end |
| 108 | + |
| 109 | +function loadBlob_Graph(dfg::AbstractDFG, entry_label::Symbol;) |
| 110 | + entry = getGraphBlobentry(dfg, entry_label) |
| 111 | + blob = getBlob(dfg, entry) |
| 112 | + return entry, blob |
| 113 | +end |
| 114 | + |
| 115 | +function saveBlob_Graph!(dfg::AbstractDFG, blob::Vector{UInt8}, entry::Blobentry) |
| 116 | + addGraphBlobentry!(dfg, entry) |
| 117 | + addBlob!(dfg, entry, blob) |
| 118 | + return entry |
| 119 | +end |
| 120 | + |
| 121 | +function saveBlob_Graph!( |
| 122 | + dfg::AbstractDFG, |
| 123 | + blob::Vector{UInt8}, |
| 124 | + entry_label::Symbol, |
| 125 | + blobstore::Symbol = :default; |
| 126 | + blobentry_kwargs..., |
| 127 | +) |
| 128 | + entry = Blobentry(entry_label, blobstore; blobentry_kwargs...) |
| 129 | + return saveBlob_Graph!(dfg, blob, entry) |
| 130 | +end |
| 131 | + |
| 132 | +function deleteBlob_Graph!(dfg::AbstractDFG, entry_label::Symbol) |
| 133 | + entry = getGraphBlobentry(dfg, entry_label) |
| 134 | + deleteGraphBlobentry!(dfg, entry_label) |
| 135 | + deleteBlob!(dfg, entry) |
| 136 | + return 2 |
| 137 | +end |
| 138 | + |
| 139 | +function loadBlob_Agent(dfg::AbstractDFG, entry_label::Symbol;) |
| 140 | + entry = getAgentBlobentry(dfg, entry_label) |
| 141 | + blob = getBlob(dfg, entry) |
| 142 | + return entry, blob |
| 143 | +end |
| 144 | + |
| 145 | +function saveBlob_Agent!(dfg::AbstractDFG, blob::Vector{UInt8}, entry::Blobentry) |
| 146 | + addAgentBlobentry!(dfg, entry) |
| 147 | + addBlob!(dfg, entry, blob) |
| 148 | + return entry |
| 149 | +end |
| 150 | + |
| 151 | +function saveBlob_Agent!( |
| 152 | + dfg::AbstractDFG, |
| 153 | + blob::Vector{UInt8}, |
| 154 | + entry_label::Symbol, |
| 155 | + blobstore::Symbol = :default; |
| 156 | + blobentry_kwargs..., |
| 157 | +) |
| 158 | + entry = Blobentry(entry_label, blobstore; blobentry_kwargs...) |
| 159 | + return saveBlob_Agent!(dfg, blob, entry) |
| 160 | +end |
| 161 | + |
| 162 | +function deleteBlob_Agent!(dfg::AbstractDFG, entry_label::Symbol) |
| 163 | + entry = getAgentBlobentry(dfg, entry_label) |
| 164 | + deleteAgentBlobentry!(dfg, entry_label) |
| 165 | + deleteBlob!(dfg, entry) |
| 166 | + return 2 |
| 167 | +end |
| 168 | + |
| 169 | +function saveImage_Variable!( |
| 170 | + dfg::AbstractDFG, |
| 171 | + variable_label::Symbol, |
| 172 | + img::AbstractMatrix, |
| 173 | + entry_label::Symbol, |
| 174 | + blobstore::Symbol = :default; |
| 175 | + entry_kwargs..., |
| 176 | +) |
| 177 | + mimeType = get(entry_kwargs, :mimeType, MIME("image/png")) |
| 178 | + format = _MIMETypes[mimeType] |
| 179 | + |
| 180 | + blob, mimeType = packBlob(format, img) |
| 181 | + |
| 182 | + size = string(length(blob)) |
| 183 | + entry = Blobentry( |
| 184 | + entry_label, |
| 185 | + blobstore; |
| 186 | + blobId = uuid4(), |
| 187 | + entry_kwargs..., |
| 188 | + size, |
| 189 | + mimeType = string(mimeType), |
| 190 | + ) |
| 191 | + |
| 192 | + return saveBlob_Variable!(dfg, variable_label, blob, entry) |
| 193 | +end |
| 194 | + |
| 195 | +function loadImage_Variable(dfg::AbstractDFG, variable_label::Symbol, entry_label::Symbol) |
| 196 | + entry, blob = loadBlob_Variable(dfg, variable_label, entry_label) |
| 197 | + return entry, unpackBlob(entry, blob) |
| 198 | +end |
0 commit comments