/** Asset storage object. Assets are binary files attached to a node. * Use `node.createAsset()` to create an asset object. Asset objects have * minimal meta information about the asset file: just subtype and * file extension. All other metadata should be stored in the node it * is attached to. * * @class Asset * @memberof jibo.kb * @param {string} [filenameOrUrl] Filename to asset on disk, or url * to asset via KB service. * @param {string} [subtype] Subtype name of asset. Defaults to `asset`. * @param {string} [ext] Optional filename extension. */ /** Create an Error with a good message from an AxiosError object * * @method jibo.kb.KnowledgeBase#_processError * @param {AxiosError} err Axios error object. * @returns {Error} Error object. * @private */ /** The filename for this asset, without any directory * information. Format of the filename is: * * `{$_id}.{$subtype}.{$ext}`. * * If the asset doesn't have an extension, `{$ext}` (and its dot * seperator) will be absent. * * @method jibo.kb.Asset#filename * @returns {string} The filename. */ /** Full path to the asset file on disk or a URL to fetch it * via the KB service. * * @method jibo.kb.Asset#fullFilenameOrURL * @returns {string} Full path filename or URL. */ /** Print useful console logs from asset objects. * * @method jibo.kb.Asset#toString * @returns {string} Full path filename or URL. */ /** Write out the data for this asset file. Data can be provided * as a readable stream, buffer, or blob. * * @method jibo.kb.Asset#save * @param {stream.Readable|Buffer|Blob} data Data to be saved in asset file. * @param {Function} [callback] Called when done. If callback is * omitted a promise is returned instead. * @returns {Promise} A promise if the callback is omitted. */ /** Set up an asset object by parsing an asset filename or * URL. Sets the `_id`, `subtype`, and `ext`. Set rootDir if full * path filename or URL. * * @method jibo.kb.Asset#setSelfFromFilenameOrURL * @param {string} filenameOrUrl Filename, full path filename, or URL. */ /** Load the binary file pointed to by this asset object. * Returns a buffer (via callback) with the contents (data) of the file. * * @method jibo.kb.Asset#load * @param {Function} [callback] Called with (err, data) when * done. If callback is omitted a promise that resolves to `data` * is returned instead. * @returns {Promise} A promise that resolves with the value of * `data` if the callback is omitted. */ /** Create a stream of the binary file this asset object points to. * Return a stream (via callback) of the contents (data) * of the file. * * @method jibo.kb.Asset#loadStream * @returns {Promise} Stream of binary asset data. */ /** Load the binary file pointed to by this asset object. * Returns a blob (via callback) with the contents (data) of the file. * * @method jibo.kb.Asset#loadBlob * @param {Function} [callback] Called with (err, data) when * done. If callback is omitted a promise that resolves to `data` * is returned instead. * @returns {Promise} A promise that resolves with the value of * `data` if the callback is omitted. */ /** Remove the asset file from disk. * * @method jibo.kb.Asset#remove * @param {Function} [callback] Called when done. If callback is * omitted a promise is returned instead. * @returns {Promise} A promise if the callback is omitted. */ /** Assemble the URL for this asset. * * @method jibo.kb.Asset#_url * @returns {string} URL * @private */ /** Saves the asset data via the KB service web interface. * * @method jibo.kb.Asset#_saveViaWeb * @private */ /** Set up an asset by parsing a filename * * @method jibo.kb.Asset#_setSelfFromFilename * @param {string} filename Filename or full path filename * @private */ /** Set up an asset from a URL * * @method jibo.kb.Asset#_setSelfFromURL * @param {string} URL * @private */ /** Remove the asset file from disk via KB service. * * @method jibo.kb.Asset#_removeViaWeb * @param {Function} callback Called when done * @private */ /** Save asset file from buffer. * * @method jibo.kb.Asset#_saveBuffer * @param {Buffer} buffer Data to be saved in asset file * @param {Function} callback Called when done * @private */ /** Save asset file from stream. * * @method jibo.kb.Asset#_saveStream * @param {stream.Readable} stream Data to be saved in asset file * @param {Function} callback Called when done * @private */ /** Loads the asset via the KB service. * * @method jibo.kb.Asset#_loadBufferViaWeb * @param {Function} callback Called with (err, data) when done * @private */ /** Loads a stream of the asset via the KB service. * * @method jibo.kb.Asset#_loadStreamViaWeb * @returns {Promise} Promise to resolve a Stream of asset * @private */