/**
* The base class of document resources, for example,
* the images referenced by the document.
*/
export class Resource {
/**
* Invoked by {@link ResourceStorage} to create a resource object.
*/
constructor(uri, data) {
this._uri = uri;
this._data = data;
}
/**
* Returns the absolute URI of this resource object.
*/
get uri() {
return this._uri;
}
/**
* Returns the ready-to-use, fully loaded, content of this resource
* object, a <code>Blob</code> or a <code>File</code>.
* <p><strong>IMPORTANT:</strong> may return <code>null</code> in case the
* {@link ResourceStorage} has no way to actually load this resource.
* without prompting the user to do so. This is for example the case of
* local files.
*/
get data() {
return this._data;
}
/**
* Returns a string representation of this resource object
* which is only useful when testing and debugging.
*/
toString() {
const size = !this.data? -1 : this.data.size;
return `${this.constructor.name}(uri='${this.uri}', \
data=<${size} bytes>)`;
}
/**
* Returns a JSON representation of this resource object
* which is only useful when testing and debugging.
*/
toJSON(key) {
const size = !this.data? -1 : this.data.size;
return { type: this.constructor.name, uri: this.uri, size: size };
}
}